我收到错误:
ActiveModel::MissingAttributeError: can't write unknown attribute `[:account_id, :list_id]`
楷模:
class Account < ActiveRecord::Base
has_many :accounts_lists
has_many :subscriptions, -> {uniq}, :through => :accounts_lists, source: :list
has_many :lists, foreign_key: 'creator_id'
end
class List < ActiveRecord::Base
has_many :accounts_lists
has_many :subscribers, -> {uniq}, :through => :accounts_lists, source: :account
belongs_to :creator, class_name: 'Account'
end
class AccountsList < ActiveRecord::Base
self.primary_key = [:account_id, :list_id]
belongs_to :account
belongs_to :list
end
我正在尝试运行种子方法并在以下命令中将列表添加到帐户:
a = Account.create(email: 'email', password: 'secret', password_confirmation: 'secret')
list1 = List.create(creator: a, list_type: music, name: "a's list 1")
a.subscriptions << list1
account.lists
由于应用程序的性质,我已经更改了多对多连接的典型名称。一个帐户可以有许多它订阅的列表,以及它是其创建者的许多列表。
List
我相信,从错误的措辞方式来看,很难找到正确的关联来subscriptions
将Account
.
有任何想法吗?