Changeset 8219
- Timestamp:
- 11/26/07 22:46:11 (1 year ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/fixtures.rb (modified) (2 diffs)
- trunk/activerecord/test/fixtures_test.rb (modified) (2 diffs)
- trunk/activerecord/test/fixtures/db_definitions/schema.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/parrot.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/parrots.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r8218 r8219 1 1 *SVN* 2 3 * Foxy fixtures: support single-table inheritance. #10234 [tom] 2 4 3 5 * Foxy fixtures: allow mixed usage to make migration easier and more attractive. #10004 [lotswholetime] trunk/activerecord/lib/active_record/fixtures.rb
r8218 r8219 582 582 end 583 583 584 model_class.reflect_on_all_associations.each do |association| 584 # If STI is used, find the correct subclass for association reflection 585 reflection_class = 586 if row.include?(inheritance_column_name) 587 row[inheritance_column_name].constantize rescue model_class 588 else 589 model_class 590 end 591 592 reflection_class.reflect_on_all_associations.each do |association| 585 593 case association.macro 586 594 when :belongs_to … … 649 657 column_names.include?(name) 650 658 end 659 end 660 661 def inheritance_column_name 662 @inheritance_column_name ||= model_class && model_class.inheritance_column 651 663 end 652 664 trunk/activerecord/test/fixtures_test.rb
r8218 r8219 563 563 assert_equal(parrots(:louis), treasures(:ruby).looter) 564 564 end 565 565 566 566 def test_only_generates_a_pk_if_necessary 567 567 m = Matey.find(:first) … … 569 569 m.target = pirates(:redbeard) 570 570 end 571 572 def test_supports_sti 573 assert_kind_of DeadParrot, parrots(:polly) 574 assert_equal pirates(:blackbeard), parrots(:polly).killer 575 end 571 576 end 572 577 trunk/activerecord/test/fixtures/db_definitions/schema.rb
r8218 r8219 308 308 create_table :parrots, :force => true do |t| 309 309 t.column :name, :string 310 t.column :parrot_sti_class, :string 311 t.column :killer_id, :integer 310 312 t.column :created_at, :datetime 311 313 t.column :created_on, :datetime trunk/activerecord/test/fixtures/parrot.rb
r8170 r8219 1 1 class Parrot < ActiveRecord::Base 2 set_inheritance_column :parrot_sti_class 2 3 has_and_belongs_to_many :pirates 3 4 has_and_belongs_to_many :treasures 4 5 has_many :loots, :as => :looter 5 6 end 7 8 class LiveParrot < Parrot 9 end 10 11 class DeadParrot < Parrot 12 belongs_to :killer, :class_name => 'Pirate' 13 end trunk/activerecord/test/fixtures/parrots.yml
r8218 r8219 2 2 name: "Curious George" 3 3 treasures: diamond, sapphire 4 parrot_sti_class: LiveParrot 4 5 5 6 louis: 6 7 name: "King Louis" 7 8 treasures: [diamond, sapphire] 9 parrot_sti_class: LiveParrot 8 10 9 11 frederick: 10 12 name: $LABEL 13 parrot_sti_class: LiveParrot 11 14 12 15 polly: 13 16 id: 4 14 17 name: $LABEL 18 killer: blackbeard 15 19 treasures: sapphire, ruby 20 parrot_sti_class: DeadParrot 16 21 17 22 DEFAULTS: &DEFAULTS 18 23 treasures: sapphire, ruby 24 parrot_sti_class: LiveParrot 19 25 20 26 davey: