activerecord 2.2.3 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (120) hide show
  1. data/CHANGELOG +438 -396
  2. data/Rakefile +4 -2
  3. data/lib/active_record.rb +46 -43
  4. data/lib/active_record/association_preload.rb +34 -19
  5. data/lib/active_record/associations.rb +193 -251
  6. data/lib/active_record/associations/association_collection.rb +38 -21
  7. data/lib/active_record/associations/association_proxy.rb +11 -4
  8. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +2 -2
  9. data/lib/active_record/associations/has_many_association.rb +2 -2
  10. data/lib/active_record/associations/has_many_through_association.rb +8 -8
  11. data/lib/active_record/associations/has_one_association.rb +11 -2
  12. data/lib/active_record/attribute_methods.rb +1 -0
  13. data/lib/active_record/autosave_association.rb +349 -0
  14. data/lib/active_record/base.rb +292 -106
  15. data/lib/active_record/batches.rb +73 -0
  16. data/lib/active_record/calculations.rb +34 -16
  17. data/lib/active_record/callbacks.rb +37 -8
  18. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +16 -0
  19. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +3 -0
  20. data/lib/active_record/connection_adapters/abstract/database_statements.rb +103 -15
  21. data/lib/active_record/connection_adapters/abstract/query_cache.rb +6 -6
  22. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +28 -25
  23. data/lib/active_record/connection_adapters/abstract_adapter.rb +29 -5
  24. data/lib/active_record/connection_adapters/mysql_adapter.rb +50 -21
  25. data/lib/active_record/connection_adapters/postgresql_adapter.rb +26 -41
  26. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
  27. data/lib/active_record/connection_adapters/sqlite_adapter.rb +41 -21
  28. data/lib/active_record/dirty.rb +1 -1
  29. data/lib/active_record/dynamic_scope_match.rb +25 -0
  30. data/lib/active_record/fixtures.rb +193 -198
  31. data/lib/active_record/locale/en.yml +1 -1
  32. data/lib/active_record/locking/optimistic.rb +33 -0
  33. data/lib/active_record/migration.rb +8 -2
  34. data/lib/active_record/named_scope.rb +13 -6
  35. data/lib/active_record/nested_attributes.rb +329 -0
  36. data/lib/active_record/query_cache.rb +25 -13
  37. data/lib/active_record/reflection.rb +6 -1
  38. data/lib/active_record/schema_dumper.rb +2 -0
  39. data/lib/active_record/serialization.rb +3 -1
  40. data/lib/active_record/serializers/json_serializer.rb +19 -0
  41. data/lib/active_record/serializers/xml_serializer.rb +28 -13
  42. data/lib/active_record/session_store.rb +318 -0
  43. data/lib/active_record/test_case.rb +15 -9
  44. data/lib/active_record/timestamp.rb +2 -2
  45. data/lib/active_record/transactions.rb +58 -8
  46. data/lib/active_record/validations.rb +29 -24
  47. data/lib/active_record/version.rb +2 -2
  48. data/test/cases/ar_schema_test.rb +0 -1
  49. data/test/cases/associations/belongs_to_associations_test.rb +35 -131
  50. data/test/cases/associations/cascaded_eager_loading_test.rb +8 -0
  51. data/test/cases/associations/eager_load_nested_include_test.rb +29 -0
  52. data/test/cases/associations/eager_test.rb +137 -7
  53. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +45 -7
  54. data/test/cases/associations/has_many_associations_test.rb +110 -149
  55. data/test/cases/associations/has_many_through_associations_test.rb +39 -7
  56. data/test/cases/associations/has_one_associations_test.rb +39 -92
  57. data/test/cases/associations/has_one_through_associations_test.rb +34 -3
  58. data/test/cases/associations/inner_join_association_test.rb +0 -5
  59. data/test/cases/associations/join_model_test.rb +5 -7
  60. data/test/cases/attribute_methods_test.rb +13 -1
  61. data/test/cases/autosave_association_test.rb +901 -0
  62. data/test/cases/base_test.rb +41 -21
  63. data/test/cases/batches_test.rb +61 -0
  64. data/test/cases/calculations_test.rb +37 -17
  65. data/test/cases/callbacks_test.rb +43 -5
  66. data/test/cases/connection_pool_test.rb +25 -0
  67. data/test/cases/copy_table_test_sqlite.rb +11 -0
  68. data/test/cases/datatype_test_postgresql.rb +1 -0
  69. data/test/cases/defaults_test.rb +37 -26
  70. data/test/cases/dirty_test.rb +26 -2
  71. data/test/cases/finder_test.rb +79 -44
  72. data/test/cases/fixtures_test.rb +15 -19
  73. data/test/cases/helper.rb +26 -19
  74. data/test/cases/inheritance_test.rb +2 -2
  75. data/test/cases/json_serialization_test.rb +1 -1
  76. data/test/cases/locking_test.rb +23 -5
  77. data/test/cases/method_scoping_test.rb +126 -3
  78. data/test/cases/migration_test.rb +253 -237
  79. data/test/cases/named_scope_test.rb +73 -3
  80. data/test/cases/nested_attributes_test.rb +509 -0
  81. data/test/cases/query_cache_test.rb +0 -4
  82. data/test/cases/reflection_test.rb +13 -3
  83. data/test/cases/reload_models_test.rb +3 -1
  84. data/test/cases/repair_helper.rb +50 -0
  85. data/test/cases/schema_dumper_test.rb +0 -1
  86. data/test/cases/transactions_test.rb +177 -12
  87. data/test/cases/validations_i18n_test.rb +288 -294
  88. data/test/cases/validations_test.rb +230 -180
  89. data/test/cases/xml_serialization_test.rb +19 -1
  90. data/test/fixtures/fixture_database.sqlite3 +0 -0
  91. data/test/fixtures/fixture_database_2.sqlite3 +0 -0
  92. data/test/fixtures/member_types.yml +6 -0
  93. data/test/fixtures/members.yml +3 -1
  94. data/test/fixtures/people.yml +10 -1
  95. data/test/fixtures/toys.yml +4 -0
  96. data/test/models/author.rb +1 -2
  97. data/test/models/bird.rb +3 -0
  98. data/test/models/category.rb +1 -0
  99. data/test/models/company.rb +3 -0
  100. data/test/models/developer.rb +12 -0
  101. data/test/models/event.rb +3 -0
  102. data/test/models/member.rb +1 -0
  103. data/test/models/member_detail.rb +1 -0
  104. data/test/models/member_type.rb +3 -0
  105. data/test/models/owner.rb +2 -1
  106. data/test/models/parrot.rb +2 -0
  107. data/test/models/person.rb +6 -0
  108. data/test/models/pet.rb +2 -1
  109. data/test/models/pirate.rb +55 -1
  110. data/test/models/post.rb +6 -0
  111. data/test/models/project.rb +1 -0
  112. data/test/models/reply.rb +6 -0
  113. data/test/models/ship.rb +8 -1
  114. data/test/models/ship_part.rb +5 -0
  115. data/test/models/topic.rb +13 -1
  116. data/test/models/toy.rb +4 -0
  117. data/test/schema/schema.rb +35 -2
  118. metadata +70 -9
  119. data/test/fixtures/fixture_database.sqlite +0 -0
  120. data/test/fixtures/fixture_database_2.sqlite +0 -0
@@ -31,11 +31,22 @@ class XmlSerializationTest < ActiveRecord::TestCase
31
31
  assert_match %r{<created_at}, @xml
32
32
  end
33
33
 
34
+ def test_should_allow_camelized_tags
35
+ @xml = Contact.new.to_xml :root => 'xml_contact', :camelize => true
36
+ assert_match %r{^<XmlContact>}, @xml
37
+ assert_match %r{</XmlContact>$}, @xml
38
+ assert_match %r{<CreatedAt}, @xml
39
+ end
40
+
41
+ def test_should_allow_skipped_types
42
+ @xml = Contact.new(:age => 25).to_xml :skip_types => true
43
+ assert %r{<age>25</age>}.match(@xml)
44
+ end
45
+
34
46
  def test_should_include_yielded_additions
35
47
  @xml = Contact.new.to_xml do |xml|
36
48
  xml.creator "David"
37
49
  end
38
-
39
50
  assert_match %r{<creator>David</creator>}, @xml
40
51
  end
41
52
  end
@@ -138,6 +149,13 @@ class DatabaseConnectedXmlSerializationTest < ActiveRecord::TestCase
138
149
  assert_match %r{<hello-post type="StiPost">}, xml
139
150
  end
140
151
 
152
+ def test_included_associations_should_skip_types
153
+ xml = authors(:david).to_xml :include=>:hello_posts, :indent => 0, :skip_types => true
154
+ assert_match %r{<hello-posts>}, xml
155
+ assert_match %r{<hello-post>}, xml
156
+ assert_match %r{<hello-post>}, xml
157
+ end
158
+
141
159
  def test_methods_are_called_on_object
142
160
  xml = authors(:david).to_xml :methods => :label, :indent => 0
143
161
  assert_match %r{<label>.*</label>}, xml
@@ -0,0 +1,6 @@
1
+ founding:
2
+ id: 1
3
+ name: Founding
4
+ provisional:
5
+ id: 2
6
+ name: Provisional
@@ -1,4 +1,6 @@
1
1
  groucho:
2
2
  name: Groucho Marx
3
+ member_type_id: 1
3
4
  some_other_guy:
4
- name: Englebert Humperdink
5
+ name: Englebert Humperdink
6
+ member_type_id: 2
@@ -1,6 +1,15 @@
1
1
  michael:
2
2
  id: 1
3
3
  first_name: Michael
4
+ primary_contact_id: 2
5
+ gender: M
4
6
  david:
5
7
  id: 2
6
- first_name: David
8
+ first_name: David
9
+ primary_contact_id: 3
10
+ gender: M
11
+ susan:
12
+ id: 3
13
+ first_name: Susan
14
+ primary_contact_id: 2
15
+ gender: F
@@ -0,0 +1,4 @@
1
+ bone:
2
+ toy_id: 1
3
+ name: Bone
4
+ pet_id: 1
@@ -1,6 +1,7 @@
1
1
  class Author < ActiveRecord::Base
2
2
  has_many :posts
3
3
  has_many :posts_with_comments, :include => :comments, :class_name => "Post"
4
+ has_many :popular_grouped_posts, :include => :comments, :class_name => "Post", :group => "type", :having => "SUM(comments_count) > 1", :select => "type"
4
5
  has_many :posts_with_comments_sorted_by_comment_id, :include => :comments, :class_name => "Post", :order => 'comments.id'
5
6
  has_many :posts_sorted_by_id_limited, :class_name => "Post", :order => 'posts.id', :limit => 1
6
7
  has_many :posts_with_categories, :include => :categories, :class_name => "Post"
@@ -24,8 +25,6 @@ class Author < ActiveRecord::Base
24
25
  has_many :comments_with_order_and_conditions, :through => :posts, :source => :comments, :order => 'comments.body', :conditions => "comments.body like 'Thank%'"
25
26
  has_many :comments_with_include, :through => :posts, :source => :comments, :include => :post
26
27
 
27
- has_many :thinking_posts, :class_name => 'Post', :conditions => { :title => 'So I was thinking' }
28
- has_many :welcome_posts, :class_name => 'Post', :conditions => { :title => 'Welcome to the weblog' }
29
28
 
30
29
  has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
31
30
  has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1
@@ -0,0 +1,3 @@
1
+ class Bird < ActiveRecord::Base
2
+ validates_presence_of :name
3
+ end
@@ -14,6 +14,7 @@ class Category < ActiveRecord::Base
14
14
  :class_name => 'Post',
15
15
  :conditions => { :title => 'Yet Another Testing Title' }
16
16
 
17
+ has_and_belongs_to_many :popular_grouped_posts, :class_name => "Post", :group => "posts.type", :having => "sum(comments.post_id) > 2", :include => :comments
17
18
  has_and_belongs_to_many :posts_gruoped_by_title, :class_name => "Post", :group => "title", :select => "title"
18
19
 
19
20
  def self.what_are_you
@@ -37,6 +37,7 @@ class Firm < Company
37
37
  has_many :clients, :order => "id", :dependent => :destroy, :counter_sql =>
38
38
  "SELECT COUNT(*) FROM companies WHERE firm_id = 1 " +
39
39
  "AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )"
40
+ has_many :unsorted_clients, :class_name => "Client"
40
41
  has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
41
42
  has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
42
43
  has_many :unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false
@@ -69,6 +70,7 @@ class Firm < Company
69
70
  has_one :account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name=>'Account'
70
71
  has_one :readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true
71
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
72
74
  end
73
75
 
74
76
  class DependentFirm < Company
@@ -80,6 +82,7 @@ class ExclusivelyDependentFirm < Company
80
82
  has_one :account, :foreign_key => "firm_id", :dependent => :delete
81
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.'"
82
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.'}
83
86
  end
84
87
 
85
88
  class Client < Company
@@ -77,3 +77,15 @@ class DeveloperWithBeforeDestroyRaise < ActiveRecord::Base
77
77
  raise if projects.empty?
78
78
  end
79
79
  end
80
+
81
+ class DeveloperOrderedBySalary < ActiveRecord::Base
82
+ self.table_name = 'developers'
83
+ default_scope :order => 'salary DESC'
84
+ named_scope :by_name, :order => 'name DESC'
85
+
86
+ def self.all_ordered_by_name
87
+ with_scope(:find => { :order => 'name DESC' }) do
88
+ find(:all)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,3 @@
1
+ class Event < ActiveRecord::Base
2
+ validates_uniqueness_of :title
3
+ end
@@ -8,4 +8,5 @@ class Member < ActiveRecord::Base
8
8
  has_one :sponsor_club, :through => :sponsor
9
9
  has_one :member_detail
10
10
  has_one :organization, :through => :member_detail
11
+ belongs_to :member_type
11
12
  end
@@ -1,4 +1,5 @@
1
1
  class MemberDetail < ActiveRecord::Base
2
2
  belongs_to :member
3
3
  belongs_to :organization
4
+ has_one :member_type, :through => :member
4
5
  end
@@ -0,0 +1,3 @@
1
+ class MemberType < ActiveRecord::Base
2
+ has_many :members
3
+ end
@@ -1,4 +1,5 @@
1
1
  class Owner < ActiveRecord::Base
2
2
  set_primary_key :owner_id
3
3
  has_many :pets
4
- end
4
+ has_many :toys, :through => :pets
5
+ end
@@ -4,6 +4,8 @@ class Parrot < ActiveRecord::Base
4
4
  has_and_belongs_to_many :treasures
5
5
  has_many :loots, :as => :looter
6
6
  alias_attribute :title, :name
7
+
8
+ validates_presence_of :name
7
9
  end
8
10
 
9
11
  class LiveParrot < Parrot
@@ -7,4 +7,10 @@ class Person < ActiveRecord::Base
7
7
  has_many :jobs, :through => :references
8
8
  has_one :favourite_reference, :class_name => 'Reference', :conditions => ['favourite=?', true]
9
9
  has_many :posts_with_comments_sorted_by_comment_id, :through => :readers, :source => :post, :include => :comments, :order => 'comments.id'
10
+
11
+ belongs_to :primary_contact, :class_name => 'Person'
12
+ has_many :agents, :class_name => 'Person', :foreign_key => 'primary_contact_id'
13
+
14
+ named_scope :males, :conditions => { :gender => 'M' }
15
+ named_scope :females, :conditions => { :gender => 'F' }
10
16
  end
@@ -1,4 +1,5 @@
1
1
  class Pet < ActiveRecord::Base
2
2
  set_primary_key :pet_id
3
3
  belongs_to :owner
4
- end
4
+ has_many :toys
5
+ end
@@ -1,9 +1,63 @@
1
1
  class Pirate < ActiveRecord::Base
2
2
  belongs_to :parrot
3
3
  has_and_belongs_to_many :parrots
4
- has_many :treasures, :as => :looter
4
+ has_and_belongs_to_many :parrots_with_method_callbacks, :class_name => "Parrot",
5
+ :before_add => :log_before_add,
6
+ :after_add => :log_after_add,
7
+ :before_remove => :log_before_remove,
8
+ :after_remove => :log_after_remove
9
+ has_and_belongs_to_many :parrots_with_proc_callbacks, :class_name => "Parrot",
10
+ :before_add => proc {|p,pa| p.ship_log << "before_adding_proc_parrot_#{pa.id || '<new>'}"},
11
+ :after_add => proc {|p,pa| p.ship_log << "after_adding_proc_parrot_#{pa.id || '<new>'}"},
12
+ :before_remove => proc {|p,pa| p.ship_log << "before_removing_proc_parrot_#{pa.id}"},
13
+ :after_remove => proc {|p,pa| p.ship_log << "after_removing_proc_parrot_#{pa.id}"}
5
14
 
15
+ has_many :treasures, :as => :looter
6
16
  has_many :treasure_estimates, :through => :treasures, :source => :price_estimates
7
17
 
18
+ # These both have :autosave enabled because accepts_nested_attributes_for is used on them.
19
+ has_one :ship
20
+ has_many :birds
21
+ has_many :birds_with_method_callbacks, :class_name => "Bird",
22
+ :before_add => :log_before_add,
23
+ :after_add => :log_after_add,
24
+ :before_remove => :log_before_remove,
25
+ :after_remove => :log_after_remove
26
+ has_many :birds_with_proc_callbacks, :class_name => "Bird",
27
+ :before_add => proc {|p,b| p.ship_log << "before_adding_proc_bird_#{b.id || '<new>'}"},
28
+ :after_add => proc {|p,b| p.ship_log << "after_adding_proc_bird_#{b.id || '<new>'}"},
29
+ :before_remove => proc {|p,b| p.ship_log << "before_removing_proc_bird_#{b.id}"},
30
+ :after_remove => proc {|p,b| p.ship_log << "after_removing_proc_bird_#{b.id}"}
31
+
32
+ accepts_nested_attributes_for :parrots, :birds, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
33
+ accepts_nested_attributes_for :ship, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
34
+ accepts_nested_attributes_for :parrots_with_method_callbacks, :parrots_with_proc_callbacks,
35
+ :birds_with_method_callbacks, :birds_with_proc_callbacks, :allow_destroy => true
36
+
8
37
  validates_presence_of :catchphrase
38
+
39
+ def ship_log
40
+ @ship_log ||= []
41
+ end
42
+
43
+ private
44
+ def log_before_add(record)
45
+ log(record, "before_adding_method")
46
+ end
47
+
48
+ def log_after_add(record)
49
+ log(record, "after_adding_method")
50
+ end
51
+
52
+ def log_before_remove(record)
53
+ log(record, "before_removing_method")
54
+ end
55
+
56
+ def log_after_remove(record)
57
+ log(record, "after_removing_method")
58
+ end
59
+
60
+ def log(record, callback)
61
+ ship_log << "#{callback}_#{record.class.name.downcase}_#{record.id || '<new>'}"
62
+ end
9
63
  end
@@ -19,6 +19,12 @@ class Post < ActiveRecord::Base
19
19
 
20
20
  has_one :last_comment, :class_name => 'Comment', :order => 'id desc'
21
21
 
22
+ named_scope :with_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'SpecialComment'} }
23
+ named_scope :with_very_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'VerySpecialComment'} }
24
+ named_scope :with_post, lambda {|post_id|
25
+ { :joins => :comments, :conditions => {:comments => {:post_id => post_id} } }
26
+ }
27
+
22
28
  has_many :comments, :order => "body" do
23
29
  def find_most_recent
24
30
  find(:first, :order => "id DESC")
@@ -13,6 +13,7 @@ class Project < ActiveRecord::Base
13
13
  :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || '<new>'}"},
14
14
  :before_remove => Proc.new {|o, r| o.developers_log << "before_removing#{r.id}"},
15
15
  :after_remove => Proc.new {|o, r| o.developers_log << "after_removing#{r.id}"}
16
+ has_and_belongs_to_many :well_payed_salary_groups, :class_name => "Developer", :group => "salary", :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary"
16
17
 
17
18
  attr_accessor :developers_log
18
19
 
@@ -37,3 +37,9 @@ end
37
37
  class SillyReply < Reply
38
38
  belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
39
39
  end
40
+
41
+ module Web
42
+ class Reply < Web::Topic
43
+ belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true, :class_name => 'Web::Topic'
44
+ end
45
+ end
@@ -1,3 +1,10 @@
1
1
  class Ship < ActiveRecord::Base
2
2
  self.record_timestamps = false
3
- end
3
+
4
+ belongs_to :pirate
5
+ has_many :parts, :class_name => 'ShipPart', :autosave => true
6
+
7
+ accepts_nested_attributes_for :pirate, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
8
+
9
+ validates_presence_of :name
10
+ end
@@ -0,0 +1,5 @@
1
+ class ShipPart < ActiveRecord::Base
2
+ belongs_to :ship
3
+
4
+ validates_presence_of :name
5
+ end
@@ -1,9 +1,13 @@
1
1
  class Topic < ActiveRecord::Base
2
2
  named_scope :base
3
3
  named_scope :written_before, lambda { |time|
4
- { :conditions => ['written_on < ?', time] }
4
+ if time
5
+ { :conditions => ['written_on < ?', time] }
6
+ end
5
7
  }
6
8
  named_scope :approved, :conditions => {:approved => true}
9
+ named_scope :rejected, :conditions => {:approved => false}
10
+
7
11
  named_scope :by_lifo, :conditions => {:author_name => 'lifo'}
8
12
 
9
13
  named_scope :approved_as_hash_condition, :conditions => {:topics => {:approved => true}}
@@ -31,6 +35,8 @@ class Topic < ActiveRecord::Base
31
35
  end
32
36
  named_scope :named_extension, :extend => NamedExtension
33
37
  named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne]
38
+
39
+ named_scope :by_rejected_ids, lambda {{ :conditions => { :id => all(:conditions => {:approved => false}).map(&:id) } }}
34
40
 
35
41
  has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
36
42
  serialize :content
@@ -67,3 +73,9 @@ class Topic < ActiveRecord::Base
67
73
  end
68
74
  end
69
75
  end
76
+
77
+ module Web
78
+ class Topic < ActiveRecord::Base
79
+ has_many :replies, :dependent => :destroy, :foreign_key => "parent_id", :class_name => 'Web::Reply'
80
+ end
81
+ end
@@ -0,0 +1,4 @@
1
+ class Toy < ActiveRecord::Base
2
+ set_primary_key :toy_id
3
+ belongs_to :pet
4
+ end
@@ -55,6 +55,11 @@ ActiveRecord::Schema.define do
55
55
  t.binary :data
56
56
  end
57
57
 
58
+ create_table :birds, :force => true do |t|
59
+ t.string :name
60
+ t.integer :pirate_id
61
+ end
62
+
58
63
  create_table :books, :force => true do |t|
59
64
  t.column :name, :string
60
65
  end
@@ -150,10 +155,19 @@ ActiveRecord::Schema.define do
150
155
  t.integer :course_id, :null => false
151
156
  end
152
157
 
158
+ create_table :events, :force => true do |t|
159
+ t.string :title, :limit => 5
160
+ end
161
+
153
162
  create_table :funny_jokes, :force => true do |t|
154
163
  t.string :name
155
164
  end
156
165
 
166
+ create_table :goofy_string_id, :force => true, :id => false do |t|
167
+ t.string :id, :null => false
168
+ t.string :info
169
+ end
170
+
157
171
  create_table :items, :force => true do |t|
158
172
  t.column :name, :integer
159
173
  end
@@ -195,6 +209,7 @@ ActiveRecord::Schema.define do
195
209
 
196
210
  create_table :members, :force => true do |t|
197
211
  t.string :name
212
+ t.integer :member_type_id
198
213
  end
199
214
 
200
215
  create_table :member_details, :force => true do |t|
@@ -210,6 +225,10 @@ ActiveRecord::Schema.define do
210
225
  t.string :type
211
226
  end
212
227
 
228
+ create_table :member_types, :force => true do |t|
229
+ t.string :name
230
+ end
231
+
213
232
  create_table :references, :force => true do |t|
214
233
  t.integer :person_id
215
234
  t.integer :job_id
@@ -247,6 +266,7 @@ ActiveRecord::Schema.define do
247
266
  t.decimal :world_population, :precision => 10, :scale => 0
248
267
  t.decimal :my_house_population, :precision => 2, :scale => 0
249
268
  t.decimal :decimal_number_with_default, :precision => 3, :scale => 2, :default => 2.78
269
+ t.float :temperature
250
270
  end
251
271
 
252
272
  create_table :orders, :force => true do |t|
@@ -293,8 +313,10 @@ ActiveRecord::Schema.define do
293
313
  end
294
314
 
295
315
  create_table :people, :force => true do |t|
296
- t.string :first_name, :null => false
297
- t.integer :lock_version, :null => false, :default => 0
316
+ t.string :first_name, :null => false
317
+ t.references :primary_contact
318
+ t.string :gender, :limit => 1
319
+ t.integer :lock_version, :null => false, :default => 0
298
320
  end
299
321
 
300
322
  create_table :pets, :primary_key => :pet_id ,:force => true do |t|
@@ -343,12 +365,18 @@ ActiveRecord::Schema.define do
343
365
 
344
366
  create_table :ships, :force => true do |t|
345
367
  t.string :name
368
+ t.integer :pirate_id
346
369
  t.datetime :created_at
347
370
  t.datetime :created_on
348
371
  t.datetime :updated_at
349
372
  t.datetime :updated_on
350
373
  end
351
374
 
375
+ create_table :ship_parts, :force => true do |t|
376
+ t.string :name
377
+ t.integer :ship_id
378
+ end
379
+
352
380
  create_table :sponsors, :force => true do |t|
353
381
  t.integer :club_id
354
382
  t.integer :sponsorable_id
@@ -397,6 +425,11 @@ ActiveRecord::Schema.define do
397
425
  t.column :taggings_count, :integer, :default => 0
398
426
  end
399
427
 
428
+ create_table :toys, :primary_key => :toy_id ,:force => true do |t|
429
+ t.string :name
430
+ t.integer :pet_id, :integer
431
+ end
432
+
400
433
  create_table :treasures, :force => true do |t|
401
434
  t.column :name, :string
402
435
  t.column :looter_id, :integer