This project is archived and is in readonly mode.

#2795 ✓wontfix
José Valim

has_one with a belongs_to as source association

Reported by José Valim | June 12th, 2009 @ 08:35 PM | in 2.x

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

  class City
    belongs_to :country

  class Country

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 => [" = ?", "Brazil"])

However, as I talked with Pratik and Koz on IRC, we could simply do this:

  House.all(:include => { :city => :country }, :conditions => [" = ?", "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.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket