首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Mailboxer时如何添加depentent::destroy

使用Mailboxer时如何添加depentent::destroy
EN

Stack Overflow用户
提问于 2016-09-09 16:19:34
回答 1查看 36关注 0票数 0

如何在user.rb中添加depentent::destroy来销毁使用mailboxer创建的用户之间的消息?

我有这些表和列。

mailboxer_conversations

id | subject | created_at | updated_at

mailboxer_notifications

id |类型| body | subject | sender_id | sender_type | conversation_id |草稿| notification_code | notified_object_id | notified_object_type |附件| updated_at | created_at |全局| expires | sender_name

mailboxer_receipts

id | receiver_id | receiver_type | notification_id | is_read |垃圾桶|已删除| mailbox_type | created_at | updated_at

我做到了

(user.rb)

代码语言:javascript
复制
has_many :messages, :class_name => "Mailboxer::Message", :as => :sender
        has_many :receipts, -> { order(:created_at => :desc, :id => :desc) }, :class_name => "Mailboxer::Receipt", dependent: :destroy, as: :receiver

has_many :notifications, -> { where( notified_object_type: 'Assignment') },
        foreign_key: "notified_object_id", dependent: :destroy,
        class_name: "Mailboxer::Notification"

但它并没有起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-09 17:03:26

您必须在关联的belongs_to部分使用dependent: :destroy

所以用户has_many :notifications,在通知模型中应该是belongs_to :user, dependent: :destroy

因为现在它说,如果有人删除了通知,用户也将被销毁。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39406971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档