Rails,如何为嵌套模型集设置依赖销毁?
我有以下模型:
User
Permission (user_id, group_id)
Group
Conversation (group_id)
ConversationParticipation (conversation_id)
我想要在我的 Permissions 模型中做的是,当权限被销毁时,根据 group_id 和 user_id 删除所有相关的 ConversationParticipations。
我尝试过这个:
class Permission < ActiveRecord::Base
has_many :conversation_participations, :through => :group, :source => :conversations, :dependent => :destroy
但这似乎还没有解决问题。建议?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
has_many
的 Rails 文档的一部分您始终可以尝试回调。
Part of the Rails Documentation for
has_many
You could always try callbacks.