simple refactoring
This commit is contained in:
parent
a635b9da97
commit
df7c52489a
21 changed files with 276 additions and 264 deletions
|
@ -1,15 +1,3 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: groups
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string(255) not null
|
||||
# code :string(255) not null
|
||||
# owner_id :integer not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class Group < ActiveRecord::Base
|
||||
attr_accessible :code, :name, :owner_id
|
||||
|
||||
|
@ -18,7 +6,7 @@ class Group < ActiveRecord::Base
|
|||
|
||||
validates :name, presence: true, uniqueness: true
|
||||
validates :code, presence: true, uniqueness: true
|
||||
validates :owner_id, presence: true
|
||||
validates :owner, presence: true
|
||||
|
||||
delegate :name, to: :owner, allow_nil: true, prefix: true
|
||||
|
||||
|
@ -31,6 +19,18 @@ class Group < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def users
|
||||
User.joins(:users_projects).where('users_projects.project_id' => project_ids).uniq
|
||||
User.joins(:users_projects).where(users_projects: {project_id: project_ids}).uniq
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: groups
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string(255) not null
|
||||
# code :string(255) not null
|
||||
# owner_id :integer not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue