Forum: Ruby on Rails RE: Left Joins with Rails?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Hogan, Brian P. (Guest)
on 2006-03-02 21:21
(Received via mailing list)
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

	class Googlemap < ActiveRecord::Base
		has_one :listing

Then you can do this:

def results
	@apartments = Apartment.find(:all,
		   :include =>[:googlemap]
               :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.

Joel O. (Guest)
on 2006-03-02 22:43
(Received via mailing list)
Boy am I an idiot!

Thanks guys - I finally see where I was going wrong.

- Joel
This topic is locked and can not be replied to.