This project is archived and is in readonly mode.
has_one :through produces invalid SQL
-
njakobsen
I have the same problem in rails 2.3.2
class Item has_one :default_digital_object, :through => :item_digital_objects, :source => :digital_object endItem.first.default_digital_object produces the following SQL:
@@@SELECT "digital_objects".* FROM "digital_objects" WHERE (digital_objects.item_id = 14891 )@@@
It seems to be ignoring the :through parameter.
-
Joshua White
I'm having the same issue on 2.3.2 ... I can't get has_one through on a belongs_to relationsbip
ExamRecord.rb (contains patient_id )
belongs_to :patient
has_one :history, :through => :patient
has_many :insurance_providers, :through => :patientPatient.rb
has_many :exam_records
has_many :insurance_providers
has_one :historyHistory.rb (contains patient_id)
belongs_to :patientInsuranceProvider.rb
belongs_to :patientSo on the console if I do
ExamRecord.first.insurance_providers, I get my array of insurance providers fine...
ExamRecord.first.history I get
ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source reflection macro :has_one for has_many :history, :through => :patient. Use :source to specify the source reflection.
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/reflection.rb:301:in `check_validity!' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/has_many_through_association.rb:5:in `initialize' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations.rb:1230:in `new' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations.rb:1230:in `history' from (irb):29I have tried specifying :source => :history and I get
ExamRecord.first.history ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source reflection macro :has_one for has_many :history, :through => :patient. Use :source to specify the source reflection.
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/reflection.rb:301:in `check_validity!' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/has_many_through_association.rb:5:in `initialize' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations.rb:1230:in `new' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations.rb:1230:in `history' from (irb):31Any Ideas?
-
Joshua White
Apparently this is discussed in #1149, the has_one through only works when the join is a has_many or belongs_to.
-
Jon Leighton
- Assigned user set to Aaron Patterson
- Importance changed from to
This is no longer an issue can can be closed. The behaviour is verified by the test
test_has_one_through_with_has_onewhich exists intest/cases/associations/has_one_through_associations_test.rband already passes. Thanks.