开发者

Rails, How to setup a Dependent Destroy for a nested model set? [duplicate]

This question already has answers here: Closed 10 years 开发者_JAVA百科ago.

Possible Duplicate:

Rails - Help understanding how to use :dependent => :destroy

I have the following models:

User
Permission (user_id, group_id)
Group
Conversation (group_id)
ConversationParticipation (conversation_id)

What I want to do in my Permissions model is, when a permission is destory, delete all the related ConversationParticipations based on the group_id and user_id.

I tried this:

class Permission < ActiveRecord::Base
has_many :conversation_participations, :through => :group, :source => :conversations, :dependent => :destroy

But that doesn't seem to be cutting it just yet. Suggestions?

Thanks


Part of the Rails Documentation for has_many

:dependent

If set to :destroy all the associated objects are destroyed alongside this object by calling their destroy method. If set to :delete_all all associated objects are deleted without calling their destroy method. If set to :nullify all associated objects’ foreign keys are set to NULL without calling their save callbacks. If set to :restrict this object cannot be deleted if it has any associated object.

Warning: This option is ignored when used with :through option.

You could always try callbacks.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜