scinote-web/app/models/user_notification.rb

22 lines
542 B
Ruby

class UserNotification < ActiveRecord::Base
belongs_to :user
belongs_to :notification
def self.recent_notifications(user)
Notification.joins(:user_notifications)
.where('user_notifications.user_id = ?', user.id)
.order(created_at: :DESC)
.limit(10)
end
def self.unseen_notification_count(user)
where('user_id = ? AND checked = false', user.id).count
end
def self.seen_by_user(user)
where(user: user).map do |n|
n.checked = true
n.save
end
end
end