【问题标题】:How to make has many through polymorphic associations dependent in rails 3?如何通过多态关联依赖于rails 3?
【发布时间】:2011-03-30 07:31:14
【问题描述】:

我在 rails 3 中有一个多态关系,我正在尝试使直通表依赖。处理这个问题的最佳方法是什么?

【问题讨论】:

  • 和平时一样

标签: ruby-on-rails ruby-on-rails-3 polymorphic-associations polymorphism


【解决方案1】:

有一些示例代码可以帮助您尝试此操作。但以下是如何使其工作的示例。

class Listing < ActiveRecord::Base
  has_many :activity_items, :as => :source, :dependent => :destroy
end

class ActivityItem < ActiveRecord::Base
  belongs_to :source, :polymorphic => :true
end

这应该可以按预期工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多