Improved clode layout.

This commit is contained in:
Martin Edenhofer 2016-01-15 20:09:16 +01:00
parent c848ddbc31
commit f87adf8d5b

View file

@ -425,6 +425,30 @@ returns
=begin
merge two users to one
user = User.find(123)
result = user.merge(user_id_of_duplicate_user)
returns
result = new_user_model
=end
def merge(user_id_of_duplicate_user)
# find email addresses and move them to primary user
duplicate_user = User.find(user_id_of_duplicate_user)
# merge missing attibutes
Models.merge('User', id, user_id_of_duplicate_user)
true
end
=begin
list of active users in role
result = User.of_role('Agent')
@ -436,7 +460,8 @@ returns
=end
def self.of_role(role)
User.where(active: true).joins(:roles).where( 'roles.name' => role, 'roles.active' => true ).uniq()
roles_ids = Role.where(active: true, name: role).map(&:id)
User.where(active: true).joins(:users_roles).where('roles_users.role_id IN (?)', roles_ids)
end
private