如何在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)
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"但它并没有起作用。
发布于 2016-09-09 17:03:26
您必须在关联的belongs_to部分使用dependent: :destroy。
所以用户has_many :notifications,在通知模型中应该是belongs_to :user, dependent: :destroy
因为现在它说,如果有人删除了通知,用户也将被销毁。
https://stackoverflow.com/questions/39406971
复制相似问题