Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge [6336] from trunk. References #6466, #7153.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@6337 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b1e1088ab951fe7b0ae890a919686d88d7a6290e 1 parent 579daf5
@jeremy jeremy authored
View
5 activerecord/CHANGELOG
@@ -1,3 +1,8 @@
+*SVN*
+
+* Fix has_many :through << with custom foreign keys. #6466, #7153 [naffis, Rich Collins]
+
+
*1.15.2* (February 5th, 2007)
* Pass a range in :conditions to use the SQL BETWEEN operator. #6974 [dcmanges]
View
2  activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -138,7 +138,7 @@ def construct_owner_attributes(reflection)
# 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.
View
7 activerecord/test/associations/join_model_test.rb
@@ -6,10 +6,12 @@
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 @@ def test_create_associate_when_adding_to_has_many_through
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
View
2  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',
Please sign in to comment.
Something went wrong with that request. Please try again.