Has anybody had any luck having a has_one go through a has_many relationship in the same model. I keep getting
ActiveRecord::HasOneThroughCantAssociateThroughCollection: Cannot have a has_one :through association
It seems like it would be easy take a set of has_many results and filter it down by a specific key and call it a has_one relationship.
Using rails 3.2.12
Here is my associations right now participation is a different model.
has_one :original_participation, :through => :participation
has_one :original_participant, :through => :original_participants, :foreign_key => "organization_id"
has_many :original_participants,
:through => :original_participation,
:source => :participants
I need to go through this last association and filter it down by organization_id.
ActiveRecord::HasOneThroughCantAssociateThroughCollection: Cannot have a has_one :through association 'Surveys::Participant#original_participant' where the :through association 'Surveys::Participant#original_participants' is a collection. Specify a has_one or belongs_to association in the :through option instead.
:original_participant
from a collection of:original_participants
. There is no way to know which is THE original_participant. If you want just one, then in your method you could just useoriginal_participants.first
– lilwupsterdef original_participant
original_participants.where(organization_id: id).first
end
Syntax might be off and I'm not sure where the org_id is coming from but hopefully it makes sense. – lilwupster