1 class AbstractCompany
< ActiveRecord
::Base
2 self.abstract_class
= true
5 class Company
< AbstractCompany
7 set_sequence_name
:companies_nonstd_seq
9 validates_presence_of
:name
11 has_one
:dummy_account, :foreign_key => "firm_id", :class_name => "Account"
14 "I am Jack's profound disappointment"
20 "I am Jack's innermost fears and aspirations"
25 class Company
< ::Company
28 class Firm
< ::Company
29 has_many
:clients, :class_name => 'Namespaced::Client'
32 class Client
< ::Company
37 has_many
:clients, :order => "id", :dependent => :destroy, :counter_sql =>
38 "SELECT COUNT(*) FROM companies WHERE firm_id = 1 " +
39 "AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )"
40 has_many
:unsorted_clients, :class_name => "Client"
41 has_many
:clients_sorted_desc, :class_name => "Client", :order => "id DESC"
42 has_many
:clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
43 has_many
:unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false
44 has_many
:dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy
45 has_many
:exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all
46 has_many
:limited_clients, :class_name => "Client", :order => "id", :limit => 1
47 has_many
:clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
48 has_many
:clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}'
49 has_many
:clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id"
50 has_many
:clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
51 has_many
:clients_using_counter_sql, :class_name => "Client",
52 :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
53 :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}'
54 has_many
:clients_using_zero_counter_sql, :class_name => "Client",
55 :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
56 :counter_sql => 'SELECT 0 FROM companies WHERE client_of = #{id}'
57 has_many
:no_clients_using_counter_sql, :class_name => "Client",
58 :finder_sql => 'SELECT * FROM companies WHERE client_of = 1000',
59 :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000'
60 has_many
:clients_using_finder_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE 1=1'
61 has_many
:plain_clients, :class_name => 'Client'
62 has_many
:readonly_clients, :class_name => 'Client', :readonly => true
63 has_many
:clients_using_primary_key, :class_name => 'Client',
64 :primary_key => 'name', :foreign_key => 'firm_name'
65 has_many
:clients_grouped_by_firm_id, :class_name => "Client", :group => "firm_id", :select => "firm_id"
66 has_many
:clients_grouped_by_name, :class_name => "Client", :group => "name", :select => "name"
68 has_one
:account, :foreign_key => "firm_id", :dependent => :destroy, :validate => true
69 has_one
:unvalidated_account, :foreign_key => "firm_id", :class_name => 'Account', :validate => false
70 has_one
:account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name=>'Account'
71 has_one
:readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true
72 has_one
:account_using_primary_key, :primary_key => "firm_id", :class_name => "Account"
73 has_one
:deletable_account, :foreign_key => "firm_id", :class_name => "Account", :dependent => :delete
76 class DependentFirm
< Company
77 has_one
:account, :foreign_key => "firm_id", :dependent => :nullify
78 has_many
:companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
81 class ExclusivelyDependentFirm
< Company
82 has_one
:account, :foreign_key => "firm_id", :dependent => :delete
83 has_many
:dependent_sanitized_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => "name = 'BigShot Inc.'"
84 has_many
:dependent_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => ["name = ?", 'BigShot Inc.']
85 has_many
:dependent_hash_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => {:name => 'BigShot Inc.'}
88 class Client
< Company
89 belongs_to
:firm, :foreign_key => "client_of"
90 belongs_to
:firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
91 belongs_to
:firm_with_select, :class_name => "Firm", :foreign_key => "firm_id", :select => "id"
92 belongs_to
:firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
93 belongs_to
:firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1]
94 belongs_to
:readonly_firm, :class_name => "Firm", :foreign_key => "firm_id", :readonly => true
96 # Record destruction so we can test whether firm.clients.clear has
97 # is calling client.destroy, deleting from the database, or setting
98 # foreign keys to NULL.
99 def self.destroyed_client_ids
100 @destroyed_client_ids ||= Hash
.new
{ |h
,k
| h
[k
] = [] }
103 before_destroy
do |client
|
105 Client
.destroyed_client_ids
[client
.firm
.id
] << client
.id
110 # Used to test that read and question methods are not generated for these attributes
112 read_attribute
:ruby_type
116 query_attribute
:rating
129 class SpecialClient
< Client
132 class VerySpecialClient
< SpecialClient
135 class Account
< ActiveRecord
::Base
138 def self.destroyed_account_ids
139 @destroyed_account_ids ||= Hash
.new
{ |h
,k
| h
[k
] = [] }
142 before_destroy
do |account
|
144 Account
.destroyed_account_ids
[account
.firm
.id
] << account
.id
151 errors
.add_on_empty
"credit_limit"