Module: Klastera::Concerns::ClusterUser::ClassMethods
- Defined in:
- app/models/klastera/concerns/cluster_user.rb
Instance Method Summary collapse
-
#clusters_of(organization, and_user = nil) ⇒ Object
Return a Cluster::ActiveRecord_Relation of organization (and) user.
-
#users_hash_of(organization) ⇒ Object
Return a hash of users and its clusters.
-
#users_of(organization) ⇒ Object
Return a User::ActiveRecord_Relation of organization (and) user.
Instance Method Details
#clusters_of(organization, and_user = nil) ⇒ Object
Return a Cluster::ActiveRecord_Relation of organization (and) user
15 16 17 18 |
# File 'app/models/klastera/concerns/cluster_user.rb', line 15 def clusters_of(organization,and_user=nil) and_user_id = and_user.present? ? { users: { id: and_user } } : {} ::Cluster.eager_load(cluster_users: :user).where({ organization_id: organization }.merge(and_user_id) ).order(order: :asc) end |
#users_hash_of(organization) ⇒ Object
Return a hash of users and its clusters
30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/klastera/concerns/cluster_user.rb', line 30 def users_hash_of(organization) users = {} rows = self.users_of(organization).pluck("users.id AS user_id","cluster_users.cluster_id").uniq rows.each do |row| user_id = row.first users[user_id] ||= [] users[user_id] << row.last end users end |
#users_of(organization) ⇒ Object
Return a User::ActiveRecord_Relation of organization (and) user
23 24 25 |
# File 'app/models/klastera/concerns/cluster_user.rb', line 23 def users_of(organization) ::User.eager_load(:cluster_users).where(users: { organization_id: organization } ) end |