12345678910111213141516171819202122 |
- class Notification < ApplicationRecord
- belongs_to :recipient, class_name: "User"
- belongs_to :actor, class_name: "User"
- belongs_to :notifiable, polymorphic: true
- def self.post(to:, from:, action:, notifiable:)
- recipients = Array.wrap(to)
- notifications = []
- Notification.transaction do
- notifications = recipients.uniq.each do |recipient|
- Notification.create(
- notifiable: notifiable,
- action: action,
- recipient: recipient,
- actor: from
- )
- end
- end
- notifications
- end
- end
|