Changeset 8776
- Timestamp:
- 02/02/08 03:27:31 (7 months ago)
- Files:
-
- trunk/activerecord/lib/active_record/associations/has_many_through_association.rb (modified) (1 diff)
- trunk/activerecord/test/cases/associations_test.rb (modified) (3 diffs)
- trunk/activerecord/test/fixtures/price_estimates.yml (added)
- trunk/activerecord/test/models/pirate.rb (modified) (1 diff)
- trunk/activerecord/test/models/price_estimate.rb (added)
- trunk/activerecord/test/models/treasure.rb (modified) (1 diff)
- trunk/activerecord/test/schema/schema.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/associations/has_many_through_association.rb
r8742 r8776 213 213 def construct_joins(custom_joins = nil) 214 214 polymorphic_join = nil 215 if @reflection. through_reflection.options[:as] || @reflection.source_reflection.macro == :belongs_to215 if @reflection.source_reflection.macro == :belongs_to 216 216 reflection_primary_key = @reflection.klass.primary_key 217 217 source_primary_key = @reflection.source_reflection.primary_key_name trunk/activerecord/test/cases/associations_test.rb
r8735 r8776 17 17 require 'models/person' 18 18 require 'models/reader' 19 require 'models/parrot' 20 require 'models/pirate' 21 require 'models/treasure' 22 require 'models/price_estimate' 19 23 20 24 class AssociationsTest < ActiveRecord::TestCase … … 1608 1612 1609 1613 class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase 1610 fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects 1614 fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects, 1615 :parrots, :pirates, :treasures, :price_estimates 1611 1616 1612 1617 def test_has_and_belongs_to_many … … 2144 2149 end 2145 2150 end 2151 2152 def test_has_many_through_polymorphic_has_manys_works 2153 assert_equal [10, 20].to_set, pirates(:redbeard).treasure_estimates.map(&:price).to_set 2154 end 2146 2155 end 2147 2156 trunk/activerecord/test/models/pirate.rb
r8657 r8776 2 2 belongs_to :parrot 3 3 has_and_belongs_to_many :parrots 4 has_many :loots, :as => :looter 4 has_many :treasures, :as => :looter 5 6 has_many :treasure_estimates, :through => :treasures, :source => :price_estimates 5 7 end trunk/activerecord/test/models/treasure.rb
r8657 r8776 2 2 has_and_belongs_to_many :parrots 3 3 belongs_to :looter, :polymorphic => true 4 5 has_many :price_estimates, :as => :estimate_of 4 6 end trunk/activerecord/test/schema/schema.rb
r8762 r8776 368 368 t.integer :owner_id, :integer 369 369 end 370 371 create_table :price_estimates, :force => true do |t| 372 t.string :estimate_of_type 373 t.integer :estimate_of_id 374 t.integer :price 375 end 370 376 end