1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/fixtures/company.rb
Jeremy Kemper 2076dca63f r3095@asus: jeremy | 2005-11-15 22:40:51 -0800
Ticket #1874 - Firebird adapter
 r3107@asus:  jeremy | 2005-11-16 00:06:14 -0800
 quote column aliases
 r3108@asus:  jeremy | 2005-11-16 00:08:12 -0800
 quote columns in construct_conditions_from_arguments.  update sequence_name docs.  introduce prefetched primary keys.
 r3109@asus:  jeremy | 2005-11-16 00:09:08 -0800
 double-quote rather than single-quote sqlite columns
 r3110@asus:  jeremy | 2005-11-16 00:09:56 -0800
 quote column names and use attribute_condition in validates_uniqueness_of
 r3111@asus:  jeremy | 2005-11-16 00:12:24 -0800
 Use QUOTED_TYPE constant in tests
 r3112@asus:  jeremy | 2005-11-16 00:13:28 -0800
 restrict test_inserts_with_pre_and_suffix to those adapters which support migrations
 r3113@asus:  jeremy | 2005-11-16 00:14:09 -0800
 Use QUOTED_TYPE constant in tests
 r3114@asus:  jeremy | 2005-11-16 00:14:30 -0800
 Use QUOTED_TYPE constant in tests


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3051 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-11-16 08:16:54 +00:00

73 lines
No EOL
2.9 KiB
Ruby
Executable file

class Company < ActiveRecord::Base
attr_protected :rating
set_sequence_name :companies_nonstd_seq
validates_presence_of :name
end
class Firm < Company
has_many :clients, :order => "id", :dependent => true, :counter_sql =>
"SELECT COUNT(*) FROM companies WHERE firm_id = 1 " +
"AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )"
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 :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => true
has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :exclusively_dependent => true
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}'
has_many :clients_using_counter_sql, :class_name => "Client",
:finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
:counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}'
has_many :clients_using_zero_counter_sql, :class_name => "Client",
:finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
:counter_sql => 'SELECT 0 FROM companies WHERE client_of = #{id}'
has_many :no_clients_using_counter_sql, :class_name => "Client",
:finder_sql => 'SELECT * FROM companies WHERE client_of = 1000',
:counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000'
has_one :account, :foreign_key => "firm_id", :dependent => true
end
class DependentFirm < Company
has_one :account, :foreign_key => "firm_id", :dependent => :nullify
has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
end
class Client < Company
belongs_to :firm, :foreign_key => "client_of"
belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => "1 = 1"
# Record destruction so we can test whether firm.clients.clear has
# is calling client.destroy, deleting from the database, or setting
# foreign keys to NULL.
def self.destroyed_client_ids
@destroyed_client_ids ||= Hash.new { |h,k| h[k] = [] }
end
before_destroy do |client|
if client.firm
Client.destroyed_client_ids[client.firm.id] << client.id
end
true
end
end
class SpecialClient < Client
end
class VerySpecialClient < SpecialClient
end
class Account < ActiveRecord::Base
belongs_to :firm
protected
def validate
errors.add_on_empty "credit_limit"
end
end