This patches allow you to use a has_one association with a
belongs_to as source. Assuming that House belongs to City that
belongs to Country:
class House
belongs_to :city
has_one :country, :through => :city
end
class City
belongs_to :country
end
class Country
end
The following works in Rails current versions (preload
case):
House.all(:include => :country)
The following DOES NOT work on Rails current version and is
fixed by this patch (non-preload case):
House.all(:include => :country, :conditions => ["countries.name = ?", "Brazil"])
However, as I talked with Pratik and Koz on IRC, we could simply
do this:
House.all(:include => { :city => :country }, :conditions => ["countries.name = ?", "Brazil"])
I've created the patch because I've needed this behavior in
geokit-rails, which was later fixed to work with the { :city =>
:country } case, but currently it has no use and it should not be
applied until someone comes up with a use case for it.
This ticket is just to document the patch.