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
:clients_sorted_desc, :class_name => "Client", :order => "id DESC"
41 has_many
:clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
42 has_many
:unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false
43 has_many
:dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy
44 has_many
:exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all
45 has_many
:limited_clients, :class_name => "Client", :order => "id", :limit => 1
46 has_many
:clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
47 has_many
:clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}'
48 has_many
:clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id"
49 has_many
:clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
50 has_many
:clients_using_counter_sql, :class_name => "Client",
51 :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
52 :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}'
53 has_many
:clients_using_zero_counter_sql, :class_name => "Client",
54 :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
55 :counter_sql => 'SELECT 0 FROM companies WHERE client_of = #{id}'
56 has_many
:no_clients_using_counter_sql, :class_name => "Client",
57 :finder_sql => 'SELECT * FROM companies WHERE client_of = 1000',
58 :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000'
59 has_many
:clients_using_finder_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE 1=1'
60 has_many
:plain_clients, :class_name => 'Client'
61 has_many
:readonly_clients, :class_name => 'Client', :readonly => true
62 has_many
:clients_using_primary_key, :class_name => 'Client',
63 :primary_key => 'name', :foreign_key => 'firm_name'
64 has_many
:clients_grouped_by_firm_id, :class_name => "Client", :group => "firm_id", :select => "firm_id"
65 has_many
:clients_grouped_by_name, :class_name => "Client", :group => "name", :select => "name"
67 has_one
:account, :foreign_key => "firm_id", :dependent => :destroy, :validate => true
68 has_one
:unvalidated_account, :foreign_key => "firm_id", :class_name => 'Account', :validate => false
69 has_one
:account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name=>'Account'
70 has_one
:readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true
71 has_one
:account_using_primary_key, :primary_key => "firm_id", :class_name => "Account"
74 class DependentFirm
< Company
75 has_one
:account, :foreign_key => "firm_id", :dependent => :nullify
76 has_many
:companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
79 class ExclusivelyDependentFirm
< Company
80 has_one
:account, :foreign_key => "firm_id", :dependent => :delete
81 has_many
:dependent_sanitized_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => "name = 'BigShot Inc.'"
82 has_many
:dependent_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => ["name = ?", 'BigShot Inc.']
85 class Client
< Company
86 belongs_to
:firm, :foreign_key => "client_of"
87 belongs_to
:firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
88 belongs_to
:firm_with_select, :class_name => "Firm", :foreign_key => "firm_id", :select => "id"
89 belongs_to
:firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
90 belongs_to
:firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1]
91 belongs_to
:readonly_firm, :class_name => "Firm", :foreign_key => "firm_id", :readonly => true
93 # Record destruction so we can test whether firm.clients.clear has
94 # is calling client.destroy, deleting from the database, or setting
95 # foreign keys to NULL.
96 def self.destroyed_client_ids
97 @destroyed_client_ids ||= Hash
.new
{ |h
,k
| h
[k
] = [] }
100 before_destroy
do |client
|
102 Client
.destroyed_client_ids
[client
.firm
.id
] << client
.id
107 # Used to test that read and question methods are not generated for these attributes
109 read_attribute
:ruby_type
113 query_attribute
:rating
126 class SpecialClient
< Client
129 class VerySpecialClient
< SpecialClient
132 class Account
< ActiveRecord
::Base
135 def self.destroyed_account_ids
136 @destroyed_account_ids ||= Hash
.new
{ |h
,k
| h
[k
] = [] }
139 before_destroy
do |account
|
141 Account
.destroyed_account_ids
[account
.firm
.id
] << account
.id
148 errors
.add_on_empty
"credit_limit"