Test case that I want to work:
class Thing < ActiveRecord::Base
has_many :instances
has_many :offers, :through => :instances
end
class Instance < ActiveRecord::Base
has_one :offer # potentially nil if no matching element in offers table
end
class Offer < ActiveRecord::Base
belongs_to :instance
end
Thing.find(:first).offers # => array of all offers on instances of thing
As it is, I was getting the following error:
ActiveRecord::HasManyThroughSourceAssociationMacroError: ActiveRecord::HasManyThroughSourceAssociationMacroError
from c:/InstantRails-1.0/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/reflection.rb:181:in `check_validity!'
from c:/InstantRails-1.0/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/associations/has_many_through_association.rb:6:in `initialize'
from c:/InstantRails-1.0/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/associations.rb:876:in `offers'
from (irb):93
has_one queries through the same SQL as has_many, just with the restriction that each object only has one. So, hopefully, this is an easy change for someone who gets the innards of :through.