Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

has_one with a belongs_to as source association

#2795

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.

Reported by José Valim · June 12th, 2009 @ 08:35 PM

State: wontfix
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. José Valim
    José Valim
    • State changed from new to wontfix

    August 8th, 2009 @ 12:11 PM