Module: UserNotification::ORM::Mongoid::Activist::ClassMethods
- Defined in:
- lib/user_notification/orm/mongoid/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
37 38 39 40 41 42 43 44 |
# File 'lib/user_notification/orm/mongoid/activist.rb', line 37 def acts_as_activist has_many :notifications_as_owner, :class_name => "::UserNotification::Notification", :inverse_of => :owner has_many :notifications_as_recipient, :class_name => "::UserNotification::Notification", :inverse_of => :recipient do def unread where(read: false) end end end |