Easy, but you’re confusing me a bit with your models… You have n
apartment table, but you reference Listing in the googlemap model and in
the controller. Also, you’re a little backwards there on your joins.
If you did this:
class Apartment < ActiveRecord::Base belongs_to :googlemap # because apartments HAS THE
FOREIGN KEY COLUMN
class Googlemap < ActiveRecord::Base has_one :listing end
Then you can do this:
@apartments = Apartment.find(:all,
:conditions => [“bedrooms=? AND bathrooms=?”, :params])
Or do it like you do now.
When you reference @apartment.googlemap.url, your data will be found.
However, if you use the above method, then the data will be fetched all
at once, as opposed to only upon request.
See “eager loading of associations” in the manual.
*** Also, I don’t understand your data model, but I would probably avoid
the whole mess and put the field on the apartments table… Unless
googlemaps table will have more columns than just the map URL.