diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-12-12 10:43:36 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-12-12 10:47:07 -0800 |
commit | da3891c898fd79ab28dad3ce4c9e52d876c9e4e9 (patch) | |
tree | 8f9faa6e44697f0776ab29b26110127110ec991d /activerecord | |
parent | 6e2b734f56e4c789763b9a8e3922272a004a325f (diff) | |
download | rails-da3891c898fd79ab28dad3ce4c9e52d876c9e4e9.tar.gz rails-da3891c898fd79ab28dad3ce4c9e52d876c9e4e9.tar.bz2 rails-da3891c898fd79ab28dad3ce4c9e52d876c9e4e9.zip |
make sure cached table name is a string. fixes #12582
Diffstat (limited to 'activerecord')
3 files changed, 12 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 af596a3a64..e472277374 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 @@ -20,7 +20,7 @@ module ActiveRecord::Associations::Builder def self.build(lhs_class, name, options) if options[:join_table] - KnownTable.new options[:join_table] + KnownTable.new options[:join_table].to_s else class_name = options.fetch(:class_name) { name.to_s.camelize.singularize 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 be928ec8ee..8aee7ff40e 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 @@ -570,6 +570,13 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert !developer.special_projects.include?(other_project) end + def test_symbol_join_table + developer = Developer.first + sp = developer.sym_special_projects.create("name" => "omg") + developer.reload + assert_includes developer.sym_special_projects, sp + end + def test_update_attributes_after_push_without_duplicate_join_table_rows developer = Developer.new("name" => "Kano") project = SpecialProject.create("name" => "Special Project") diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index a26de55758..2e2d8a0d37 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -36,6 +36,10 @@ class Developer < ActiveRecord::Base end has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id' + has_and_belongs_to_many :sym_special_projects, + :join_table => :developers_projects, + :association_foreign_key => 'project_id', + :class_name => 'SpecialProject' has_many :audit_logs has_many :contracts |