-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.rb
41 lines (36 loc) · 1.19 KB
/
models.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Employee < ActiveRecord::Base
acts_as_superclass
attr_accessible :first_name, :last_name, :salary, :team, :team_id
belongs_to :team
validates :first_name, :presence => true
validates :last_name, :presence => true
validates :salary, :presence => true, :numericality => { :min => 0 }
end
class Programmer < ActiveRecord::Base
inherits_from :employee
attr_accessible :languages, :language_ids
has_many :known_languages
has_many :languages, :through => :known_languages
end
class Manager < ActiveRecord::Base
inherits_from :employee
attr_accessible :bonus
validates :bonus, :numericality => true
end
class Team < ActiveRecord::Base
attr_accessible :name, :description
has_many :employees
validates :name, :presence => true, :uniqueness => true
end
class Language < ActiveRecord::Base
attr_accessible :name
has_many :known_languages
has_many :programmers, :through => :known_languages
validates :name, :presence => true, :uniqueness => true
end
class KnownLanguage < ActiveRecord::Base
belongs_to :programmer
belongs_to :language
validates :programmer_id, :presence => true
validates :language_id, :presence => true, :uniqueness => { :scope => :programmer_id }
end