aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorshiksha <shiksha@vinsol.com>2014-11-13 11:13:44 +0530
committershiksha <shiksha@vinsol.com>2014-11-13 11:13:44 +0530
commit07e0d8cc0c108b2814d5c8d29f5f3f5b1db4f696 (patch)
tree20d0d5069c800aed1b8ff5011a005d13d16f4a1e /activerecord
parent52c3a16fa07cde643af3c2200e4b87bcb470eb12 (diff)
downloadrails-07e0d8cc0c108b2814d5c8d29f5f3f5b1db4f696.tar.gz
rails-07e0d8cc0c108b2814d5c8d29f5f3f5b1db4f696.tar.bz2
rails-07e0d8cc0c108b2814d5c8d29f5f3f5b1db4f696.zip
Allow habtm class_name option to be consistent with other associations
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb2
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
index 357b28ac94..092b4ebd2f 100644
--- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
+++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
@@ -110,7 +110,7 @@ module ActiveRecord::Associations::Builder
rhs_options = {}
if options.key? :class_name
- rhs_options[:foreign_key] = options[:class_name].foreign_key
+ rhs_options[:foreign_key] = options[:class_name].to_s.foreign_key
rhs_options[:class_name] = options[:class_name]
end
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 9a57683ee3..092e85949c 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -79,6 +79,10 @@ class SubDeveloper < Developer
:association_foreign_key => "developer_id"
end
+class DeveloperWithSymbolClassName < Developer
+ has_and_belongs_to_many :projects, class_name: :ProjectWithSymbolsForKeys
+end
+
class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects,
:parrots, :pirates, :parrots_pirates, :treasures, :price_estimates, :tags, :taggings, :computers
@@ -892,4 +896,10 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_not_nil File.read(File.expand_path("../../../fixtures/developers.yml", __FILE__)).index("shared_computers")
assert_equal developers(:david).shared_computers.first, computers(:laptop)
end
+
+ def test_with_symbol_class_name
+ assert_nothing_raised NoMethodError do
+ DeveloperWithSymbolClassName.new
+ end
+ end
end