2012-10-02 18:17:12 +03:00
|
|
|
class Group < ActiveRecord::Base
|
|
|
|
attr_accessible :code, :name, :owner_id
|
|
|
|
|
|
|
|
has_many :projects
|
|
|
|
belongs_to :owner, class_name: "User"
|
|
|
|
|
|
|
|
validates :name, presence: true, uniqueness: true
|
|
|
|
validates :code, presence: true, uniqueness: true
|
2012-10-09 04:10:04 +04:00
|
|
|
validates :owner, presence: true
|
2012-10-02 19:01:40 +03:00
|
|
|
|
|
|
|
delegate :name, to: :owner, allow_nil: true, prefix: true
|
|
|
|
|
2012-10-03 13:42:17 +03:00
|
|
|
def self.search query
|
2012-10-04 13:40:40 +03:00
|
|
|
where("name LIKE :query OR code LIKE :query", query: "%#{query}%")
|
2012-10-03 13:42:17 +03:00
|
|
|
end
|
|
|
|
|
2012-10-02 19:01:40 +03:00
|
|
|
def to_param
|
|
|
|
code
|
|
|
|
end
|
2012-10-03 14:26:37 +03:00
|
|
|
|
|
|
|
def users
|
2012-10-09 04:10:04 +04:00
|
|
|
User.joins(:users_projects).where(users_projects: {project_id: project_ids}).uniq
|
2012-10-03 14:26:37 +03:00
|
|
|
end
|
2012-10-02 18:17:12 +03:00
|
|
|
end
|
2012-10-09 04:10:04 +04:00
|
|
|
|
|
|
|
# == 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
|
|
|
|
#
|
2012-10-09 11:14:17 +03:00
|
|
|
|