Преглед на файлове

Add unread notification scope. (#41)

* Add unread notification scope.

* Add Recent Scope to Notifications
darkrubyist преди 7 години
родител
ревизия
716ca1f51c
променени са 1 файла, в които са добавени 3 реда и са изтрити 0 реда
  1. 3 0
      app/models/notification.rb

+ 3 - 0
app/models/notification.rb

@@ -2,6 +2,9 @@ class Notification < ApplicationRecord
   belongs_to :recipient, class_name: "User"
   belongs_to :actor, class_name: "User"
   belongs_to :notifiable, polymorphic: true
+  
+  scope :unread, -> { where(read_at: nil) }
+  scope :recent, -> { order(created_at: :desc) }.limit(5)
 
   def self.post(to:, from:, action:, notifiable:)
     recipients = Array.wrap(to)