Module: UserNotification::ORM::ActiveRecord::Activist::ClassMethods
- Defined in:
- lib/user_notification/orm/active_record/activist.rb
Overview
Module extending classes that serve as owners
Instance Method Summary collapse
-
#acts_as_activist ⇒ Object
Adds ActiveRecord associations to model to simplify fetching so you can list notifications performed by the owner.
Instance Method Details
#acts_as_activist ⇒ Object
Adds ActiveRecord associations to model to simplify fetching so you can list notifications performed by the owner. It is completely optional. Any model can be an owner to an notification even without being an explicit acts_as_activist.
Usage:
In model:
class User < ActiveRecord::Base
include UserNotification::Model
acts_as_activist
end
In controller:
User.first.notifications
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/user_notification/orm/active_record/activist.rb', line 33 def acts_as_activist # Association of notifications as their owner. # @!method notifications_as_owner # @return [Array<Notification>] Activities which self is the owner of. has_many :notifications_as_owner, :class_name => "::UserNotification::Notification", :as => :owner # Association of notifications as their recipient. # @!method notifications_as_recipient # @return [Array<Notification>] Activities which self is the recipient of. has_many :notifications_as_recipient, :class_name => "::UserNotification::Notification", :as => :recipient do def unread where(read: false) end end end |