【发布时间】:2012-01-26 16:11:18
【问题描述】:
我有一个用于生成名为 Activity 的活动源的模型,该模型具有以下列:
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "source_id", :null => false
t.integer "activity_type", :null => false
t.text "data", :null => false
我正在尝试将每个活动附加到值得在提要中显示的不同类型的对象(例如添加到收藏夹、新连接等)。现在存在以下关联:
belongs_to :user
belongs_to :source, :polymorphic => true
我正在尝试使用 simple_enum gem 使用 source_id 作为连接对象的主键(例如收藏夹)和 activity_type 作为枚举(例如收藏夹 => 1、邀请 =>2)。
问题:我无法获得:dependent => :destroy 来处理收藏夹模型。它在一个例外中提醒我,我没有收藏夹 ID 外键,以便在我删除收藏夹后干净地删除活动。我该如何处理?
ActiveRecord::StatementInvalid (PGError: ERROR: column activities.favorite_id does not exist'
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 feed enumeration polymorphic-associations