public this repo is viewable by everyone
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixes a subtle bug when using symbols for key definitions in habtm 
associations
ddollar (author)
about 1 month ago
NZKoz (committer)
23 days ago
commit  6c1c16bfd9eb865dffa68c12c7df66d5a59a8714
tree    df4bc7789c4d1fe83085b725be0d1fe4a6223880
parent  30ad1827a66b8578cabc8f14a67c69b0ab17cf92
...
35
36
37
38
39
 
 
40
41
 
42
43
44
...
35
36
37
 
 
38
39
40
 
41
42
43
44
0
@@ -35,10 +35,10 @@ module ActiveRecord
0
             columns = @owner.connection.columns(@reflection.options[:join_table], "#{@reflection.options[:join_table]} Columns")
0
 
0
             attributes = columns.inject({}) do |attrs, column|
0
- case column.name
0
- when @reflection.primary_key_name
0
+ case column.name.to_s
0
+ when @reflection.primary_key_name.to_s
0
                   attrs[column.name] = @owner.quoted_id
0
- when @reflection.association_foreign_key
0
+ when @reflection.association_foreign_key.to_s
0
                   attrs[column.name] = record.quoted_id
0
                 else
0
                   if record.has_attribute?(column.name)
...
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
54
55
...
650
651
652
 
 
 
 
 
 
 
 
 
 
 
 
653
...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
0
@@ -50,6 +50,23 @@ class DeveloperForProjectWithAfterCreateHook < ActiveRecord::Base
0
     :foreign_key => "developer_id"
0
 end
0
 
0
+class ProjectWithSymbolsForKeys < ActiveRecord::Base
0
+ set_table_name 'projects'
0
+ has_and_belongs_to_many :developers,
0
+ :class_name => "DeveloperWithSymbolsForKeys",
0
+ :join_table => :developers_projects,
0
+ :foreign_key => :project_id,
0
+ :association_foreign_key => "developer_id"
0
+end
0
+
0
+class DeveloperWithSymbolsForKeys < ActiveRecord::Base
0
+ set_table_name 'developers'
0
+ has_and_belongs_to_many :projects,
0
+ :class_name => "ProjectWithSymbolsForKeys",
0
+ :join_table => :developers_projects,
0
+ :association_foreign_key => :project_id,
0
+ :foreign_key => "developer_id"
0
+end
0
 
0
 class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
0
   fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects,
0
@@ -650,4 +667,16 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
0
   def test_has_many_through_polymorphic_has_manys_works
0
     assert_equal [10, 20].to_set, pirates(:redbeard).treasure_estimates.map(&:price).to_set
0
   end
0
+
0
+ def test_symbols_as_keys
0
+ developer = DeveloperWithSymbolsForKeys.new(:name => 'David')
0
+ project = ProjectWithSymbolsForKeys.new(:name => 'Rails Testing')
0
+ project.developers << developer
0
+ project.save!
0
+
0
+ assert_equal 1, project.developers.size
0
+ assert_equal 1, developer.projects.size
0
+ assert_equal developer, project.developers.find(:first)
0
+ assert_equal project, developer.projects.find(:first)
0
+ end
0
 end

Comments

    No one has commented yet.