【发布时间】:2015-11-10 20:27:29
【问题描述】:
图书模型是
class Book < ActiveRecord::Base
has_many :tokens, :through => :taggings
has_many :taggings, :as => :taggable
end
代币模型是
class Token < ActiveRecord::Base
has_many :books, :through => :taggings, :source => :taggable, :source_type => "Book"
has_many :taggings
end
标签模型是
class Tagging < ActiveRecord::Base
belongs_to :token
belongs_to :taggable, :polymorphic => true
end
当我得到 Book.first.tokens OR Token.first.books 它给出错误
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: taggings.token_id: SELECT "tokens".* FROM "tokens" INNER JOIN "taggings" ON "tokens"."id" = "taggings"."token_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ?
【问题讨论】:
-
您的模型是否包含
token_id列?
标签: ruby-on-rails activerecord polymorphic-associations