2

有没有人有幸让 has_one 在同一模型中经历 has_many 关系。我不断得到

ActiveRecord::HasOneThroughCantAssociateThroughCollection: 不能有 has_one:through 关联

似乎很容易获取一组 has_many 结果并通过特定键对其进行过滤并将其称为 has_one 关系。

使用导轨 3.2.12

这是我现在的协会,参与是一种不同的模式。

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

我需要通过最后一个关联并按组织 ID 过滤它。

ActiveRecord::HasOneThroughCantAssociateThroughCollection: 不能有一个 has_one :through 关联 'Surveys::Participant#original_participant' 其中 :through 关联 'Surveys::Participant#original_participants' 是一个集合。改为在 :through 选项中指定 has_one 或 belongs_to 关联。

4

1 回答 1

2

With has_one you should not need :through There is no need for an intermediary relationship.

If I think I know what you're trying to do you have a hierarchy of tests:

has_one test_parent, :class_name => "Test", foreign_key: "child_test"

has_many tests

to call them:

@my_array_of_children = tests

@my_parents_id = test.id

etc.

于 2013-06-26T21:01:56.827 回答