Allow queries on model refs

I modified the field lookup procedure for in-memory model queries to allow queries to compare refs inside models.