diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-05 11:34:39 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-05 11:34:39 +0000 |
commit | 0e8c3b8dd974a19855f41cb319579567449461ed (patch) | |
tree | f270237dcffab0ddc4c867fc74c2f441312de72a /activerecord | |
parent | df57f53d09575f8bc6542f87a3384240b66f9b4b (diff) | |
download | rails-0e8c3b8dd974a19855f41cb319579567449461ed.tar.gz rails-0e8c3b8dd974a19855f41cb319579567449461ed.tar.bz2 rails-0e8c3b8dd974a19855f41cb319579567449461ed.zip |
Fix has_many :through << with custom foreign keys. Closes #6466, #7153.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6336 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 2 | ||||
-rw-r--r-- | activerecord/test/associations/join_model_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/fixtures/vertex.rb | 2 |
4 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index c097b38427..65b5ff2c95 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix has_many :through << with custom foreign keys. #6466, #7153 [naffis, Rich Collins] + * Test DateTime native type in migrations. #7649 [fedot] * SQLServer: correctly schema-dump tables with no indexes or descending indexes. #7333, #7703 [Jakob S, Tom Ward] diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index ce22496e6d..26559d523a 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -138,7 +138,7 @@ module ActiveRecord # Construct attributes for :through pointing to owner and associate. def construct_join_attributes(associate) - construct_owner_attributes(@reflection.through_reflection).merge(@reflection.source_reflection.association_foreign_key => associate.id) + construct_owner_attributes(@reflection.through_reflection).merge(@reflection.source_reflection.primary_key_name => associate.id) end # Associate attributes pointing to owner, quoted. diff --git a/activerecord/test/associations/join_model_test.rb b/activerecord/test/associations/join_model_test.rb index 1124a0ace0..1d2a4f6c5c 100644 --- a/activerecord/test/associations/join_model_test.rb +++ b/activerecord/test/associations/join_model_test.rb @@ -6,10 +6,12 @@ require 'fixtures/comment' require 'fixtures/author' require 'fixtures/category' require 'fixtures/categorization' +require 'fixtures/vertex' +require 'fixtures/edge' class AssociationsJoinModelTest < Test::Unit::TestCase self.use_transactional_fixtures = false - fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites + fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites, :vertices def test_has_many assert authors(:david).categories.include?(categories(:general)) @@ -414,6 +416,9 @@ class AssociationsJoinModelTest < Test::Unit::TestCase message = "Expected a Tagging in taggings collection, got #{wrong.class}.") assert_equal(count + 4, post_thinking.tags.size) assert_equal(count + 4, post_thinking.tags(true).size) + + # Raises if the wrong reflection name is used to set the Edge belongs_to + assert_nothing_raised { vertices(:vertex_1).sinks << vertices(:vertex_5) } end def test_adding_junk_to_has_many_through_should_raise_type_mismatch diff --git a/activerecord/test/fixtures/vertex.rb b/activerecord/test/fixtures/vertex.rb index f4c11144de..48bb851e62 100644 --- a/activerecord/test/fixtures/vertex.rb +++ b/activerecord/test/fixtures/vertex.rb @@ -1,7 +1,7 @@ # This class models a vertex in a directed graph. class Vertex < ActiveRecord::Base has_many :sink_edges, :class_name => 'Edge', :foreign_key => 'source_id' - has_many :sinks, :through => :sink_edges, :source => :sink + has_many :sinks, :through => :sink_edges has_and_belongs_to_many :sources, :class_name => 'Vertex', :join_table => 'edges', |