This project is archived and is in readonly mode.
Invalid has_one :through source_reflection macros
-
Pratik
- State changed from new to invalid
This was recently fixed iirc. Could you please try on edge and provide a failing test case in AR test suite if it doesn't work ?
Thanks.
-
sbwoodside
- Assigned user set to Pratik
The documentation now says:
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassM...
You can only use a :through query through a belongs_to or has_many association on the join model.
So, apparently the docs were wrong.
Also note, old bug: http://dev.rubyonrails.org/ticket/4996
-
sbwoodside
- Assigned user cleared.
Whoops, sorry didn't mean to change responsible. Anyway, since the documentation is correct now, I guess this bug should be closed.
-
Joshua White
Is there a good way to do this in the case that the join model is a has_one relationship? Or is writing SQL the best way to do it?
-
Joshua White
I tried a number of things and eventually realized I could just specify the foreign_key
so in my
History.rb
belongs_to :patientPatient.rb
has_many :exam_records
has_one :historyExamRecord.rb
belongs_to :patient
has_one :history, :foreign_key => 'patient_id'On the shell I'm finally able to say
ExamRecord.first.history -
Joshua White
Sorry, I realized my last post was incorrect, it was comparing exam_record.id to history.patient_id, and that this bug is closed, I just had to specify the primary key and all was well!
ExamRecord.rb belongs_to :patient has_one :history, :foreign_key => 'patient_id', :primary_key => 'patient_id'