2005-11-06 19:05:42 +00:00
|
|
|
module DeveloperProjectsAssociationExtension
|
|
|
|
def find_most_recent
|
|
|
|
find(:first, :order => "id DESC")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-04-11 01:10:42 +00:00
|
|
|
module DeveloperProjectsAssociationExtension2
|
|
|
|
def find_least_recent
|
|
|
|
find(:first, :order => "id ASC")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-11-24 01:04:44 +00:00
|
|
|
class Developer < ActiveRecord::Base
|
2005-11-06 19:05:42 +00:00
|
|
|
has_and_belongs_to_many :projects do
|
2005-11-03 09:06:42 +00:00
|
|
|
def find_most_recent
|
|
|
|
find(:first, :order => "id DESC")
|
|
|
|
end
|
2005-11-06 19:05:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
has_and_belongs_to_many :projects_extended_by_name,
|
|
|
|
:class_name => "Project",
|
|
|
|
:join_table => "developers_projects",
|
|
|
|
:association_foreign_key => "project_id",
|
|
|
|
:extend => DeveloperProjectsAssociationExtension
|
2005-11-03 09:06:42 +00:00
|
|
|
|
2006-04-11 01:10:42 +00:00
|
|
|
has_and_belongs_to_many :projects_extended_by_name_twice,
|
|
|
|
:class_name => "Project",
|
|
|
|
:join_table => "developers_projects",
|
|
|
|
:association_foreign_key => "project_id",
|
|
|
|
:extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
|
|
|
|
|
2005-07-03 08:52:59 +00:00
|
|
|
has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
|
2005-10-06 17:13:24 +00:00
|
|
|
|
2004-12-19 11:25:55 +00:00
|
|
|
validates_inclusion_of :salary, :in => 50000..200000
|
|
|
|
validates_length_of :name, :within => 3..20
|
2004-12-16 01:32:35 +00:00
|
|
|
end
|
2005-05-19 16:39:50 +00:00
|
|
|
|
|
|
|
DeveloperSalary = Struct.new(:amount)
|
|
|
|
class DeveloperWithAggregate < ActiveRecord::Base
|
|
|
|
self.table_name = 'developers'
|
|
|
|
composed_of :salary, :class_name => 'DeveloperSalary', :mapping => [%w(salary amount)]
|
|
|
|
end
|
2005-11-08 10:19:09 +00:00
|
|
|
|
|
|
|
class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base
|
|
|
|
self.table_name = 'developers'
|
|
|
|
has_and_belongs_to_many :projects, :join_table => 'developers_projects', :foreign_key => 'developer_id'
|
|
|
|
before_destroy :raise_if_projects_empty!
|
|
|
|
|
|
|
|
def raise_if_projects_empty!
|
|
|
|
raise if projects.empty?
|
|
|
|
end
|
|
|
|
end
|