~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activerecord/test/models/company_in_module.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
module MyApplication
2
 
  module Business
3
 
    class Company < ActiveRecord::Base
4
 
      attr_protected :rating
5
 
    end
6
 
 
7
 
    class Firm < Company
8
 
      has_many :clients, :order => "id", :dependent => :destroy
9
 
      has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
10
 
      has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
11
 
      has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
12
 
      has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
13
 
 
14
 
      has_one :account, :class_name => 'MyApplication::Billing::Account', :dependent => :destroy
15
 
    end
16
 
 
17
 
    class Client < Company
18
 
      belongs_to :firm, :foreign_key => "client_of"
19
 
      belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
20
 
 
21
 
      class Contact < ActiveRecord::Base; end
22
 
    end
23
 
 
24
 
    class Developer < ActiveRecord::Base
25
 
      has_and_belongs_to_many :projects
26
 
      validates_length_of :name, :within => (3..20)
27
 
    end
28
 
 
29
 
    class Project < ActiveRecord::Base
30
 
      has_and_belongs_to_many :developers
31
 
    end
32
 
 
33
 
  end
34
 
 
35
 
  module Billing
36
 
    class Firm < ActiveRecord::Base
37
 
      self.table_name = 'companies'
38
 
    end
39
 
 
40
 
    module Nested
41
 
      class Firm < ActiveRecord::Base
42
 
        self.table_name = 'companies'
43
 
      end
44
 
    end
45
 
 
46
 
    class Account < ActiveRecord::Base
47
 
      with_options(:foreign_key => :firm_id) do |i|
48
 
        i.belongs_to :firm, :class_name => 'MyApplication::Business::Firm'
49
 
        i.belongs_to :qualified_billing_firm, :class_name => 'MyApplication::Billing::Firm'
50
 
        i.belongs_to :unqualified_billing_firm, :class_name => 'Firm'
51
 
        i.belongs_to :nested_qualified_billing_firm, :class_name => 'MyApplication::Billing::Nested::Firm'
52
 
        i.belongs_to :nested_unqualified_billing_firm, :class_name => 'Nested::Firm'
53
 
      end
54
 
 
55
 
      protected
56
 
        def validate
57
 
          errors.add_on_empty "credit_limit"
58
 
        end
59
 
    end
60
 
  end
61
 
end