has_many通过无法修改关联

时间:2014-08-19 12:26:16

标签: ruby-on-rails ruby forms nested

我有三个模特:Almon,Bela和Lingo

class Almon < ActiveRecord::Base

  belongs_to :bela, dependent: :destroy
  has_many :lingos, through: :bela, dependent: :delete_all

  accepts_nested_attributes_for :bela
  accepts_nested_attributes_for :lingos, :allow_destroy => true
end

我正在尝试在Almon中提交嵌套表单,我正在

  

无法修改关联&#Al;#Lingos&#39;因为源反思课&#39; Lingo&#39;与Bela&#39;相关联。 via:has_many。

有谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:0)

您需要使用has_many而不是belongs_to,如下所示:

has_many :belaes, dependent: :destroy
has_many :lingoes, through: :belaes, dependent: :delete_all