我创建了一个迁移来更改我的数据模型,以便使我的Conversation模型具有多态性。
这是我的精简文件:
# deal.rb
class Deal < ActiveRecord::Base
has_many :conversations, as: :conversationable
end
# conversation.rb
class Conversation < ActiveRecord::Base
belongs_to :conversationable, polymorphic: true
end
在我的seeds.rb中,我正在拨打电话:
conversation = deal.conversations.create!(:seller_id => deal.user.id, :buyer_id => user.id)
这会产生错误:
SQLite3::SQLException: table conversations has no column named deal_id: INSERT INTO "conversations" ("buyer_id", "conversationable_id", "conversationable_type", "created_at", "deal_id", "seller_id", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)
为什么rails仍在插入deal_id?其他地方是否有我必须删除的关联残余?
当在rails控制台中运行相同的代码时,会创建具有正确关联的模型。
非常感谢。