I have three model Role
, Action
and RoleAction
with some code:
class Role < ActiveRecord::Base
has_many :users
has_many :actions, -> {where role_actions:{status: 1}}, :through => :roleActions
has_many :actions, :through => :roleActions #other context(manager, etc...)
has_many :roleActions
end
class Action < ActiveRecord::Base
has_many :actions, foreign_key: 'parent_id'
has_many :roleActions
has_many :roles, through: :roleActions
end
class RoleAction < ActiveRecord::Base
belongs_to :role
belongs_to :action
end
When I using role.actions
will get actions of role
and have status == 1
in role_actions.
But I want to when I using role.actions("manager")
(with "manager" is context name) will return all action of role.
How can I do?
Thanks!