2010-07-25 17:12:20 -04:00
|
|
|
require 'active_support/core_ext/object/with_options'
|
2009-05-13 04:10:37 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
module MyApplication
|
|
|
|
module Business
|
|
|
|
class Company < ActiveRecord::Base
|
|
|
|
attr_protected :rating
|
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Firm < Company
|
2006-03-18 15:25:50 -05:00
|
|
|
has_many :clients, :order => "id", :dependent => :destroy
|
2004-11-23 20:04:44 -05:00
|
|
|
has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
|
|
|
|
has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
|
|
|
|
has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
|
|
|
|
has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
|
|
|
|
|
2009-08-09 02:29:38 -04:00
|
|
|
has_one :account, :class_name => 'MyApplication::Billing::Account', :dependent => :destroy
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class Client < Company
|
|
|
|
belongs_to :firm, :foreign_key => "client_of"
|
|
|
|
belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
|
2008-04-07 15:44:37 -04:00
|
|
|
|
|
|
|
class Contact < ActiveRecord::Base; end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Developer < ActiveRecord::Base
|
|
|
|
has_and_belongs_to_many :projects
|
2006-10-08 21:42:09 -04:00
|
|
|
validates_length_of :name, :within => (3..20)
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Project < ActiveRecord::Base
|
|
|
|
has_and_belongs_to_many :developers
|
|
|
|
end
|
|
|
|
|
2010-02-22 05:46:45 -05:00
|
|
|
module Prefixed
|
|
|
|
def self.table_name_prefix
|
|
|
|
'prefixed_'
|
|
|
|
end
|
|
|
|
|
|
|
|
class Company < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
|
|
|
|
class Firm < Company
|
|
|
|
self.table_name = 'companies'
|
|
|
|
end
|
|
|
|
|
|
|
|
module Nested
|
|
|
|
class Company < ActiveRecord::Base
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2006-02-22 13:44:14 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
module Billing
|
2006-02-22 13:44:14 -05:00
|
|
|
class Firm < ActiveRecord::Base
|
|
|
|
self.table_name = 'companies'
|
|
|
|
end
|
|
|
|
|
|
|
|
module Nested
|
|
|
|
class Firm < ActiveRecord::Base
|
|
|
|
self.table_name = 'companies'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Account < ActiveRecord::Base
|
2006-09-15 03:02:05 -04:00
|
|
|
with_options(:foreign_key => :firm_id) do |i|
|
|
|
|
i.belongs_to :firm, :class_name => 'MyApplication::Business::Firm'
|
|
|
|
i.belongs_to :qualified_billing_firm, :class_name => 'MyApplication::Billing::Firm'
|
|
|
|
i.belongs_to :unqualified_billing_firm, :class_name => 'Firm'
|
|
|
|
i.belongs_to :nested_qualified_billing_firm, :class_name => 'MyApplication::Billing::Nested::Firm'
|
|
|
|
i.belongs_to :nested_unqualified_billing_firm, :class_name => 'Nested::Firm'
|
|
|
|
end
|
2006-02-22 13:44:14 -05:00
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
validate :check_empty_credit_limit
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
protected
|
2009-03-21 15:05:09 -04:00
|
|
|
|
|
|
|
def check_empty_credit_limit
|
|
|
|
errors.add_on_empty "credit_limit"
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|