开发者

Rails - delete one side of a one-to-many relationship

Quick question:

If I have a one-to-many relationship, such as thi开发者_StackOverflows:

class SalesPerson < ActiveRecord::Base
  has_many :deals
end

class Deal < ActiveRecord::Base
  belongs_to :sales_person
end

how can I delete a Sales Person, without negatively impacting the deals associated with them? The use-case for this would be if someone left the organization. We still need a record of the deals in the database, but that sales person record is no longer needed.

Would it just be better to have an active/inactive flag on the sales person instead?

Thanks.


For this kind of situations I've use acts_as_paranoid, basically It adds a new timestamps column: deleted_at and overrides some of your AR finders.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜