1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #14871 from kassio/kb-fixes-namespaced-habtm

Fix how to compute class name on habtm namespaced.

Conflicts:
	activerecord/CHANGELOG.md
This commit is contained in:
Rafael Mendonça França 2014-05-14 21:35:52 -03:00
commit f85371f69d
7 changed files with 43 additions and 1 deletions

View file

@ -1,3 +1,10 @@
* Fix how to calculate associated class name when using namespaced `has_and_belongs_to_many`
association.
Fixes #14709.
*Kassio Borges*
* `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
strings in column names as equal.

View file

@ -23,7 +23,11 @@ module ActiveRecord::Associations::Builder
KnownTable.new options[:join_table].to_s
else
class_name = options.fetch(:class_name) {
name.to_s.camelize.singularize
model_name = name.to_s.camelize.singularize
if parent_name = lhs_class.parent_name.presence
model_name = model_name.prepend("#{parent_name}::")
end
model_name
}
KnownClass.new lhs_class, class_name
end

View file

@ -22,6 +22,9 @@ require 'models/sponsor'
require 'models/country'
require 'models/treaty'
require 'models/vertex'
require 'models/publisher'
require 'models/publisher/article'
require 'models/publisher/magazine'
require 'active_support/core_ext/string/conversions'
class ProjectWithAfterCreateHook < ActiveRecord::Base
@ -848,4 +851,13 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
def test_custom_join_table
assert_equal 'edges', Vertex.reflect_on_association(:sources).join_table
end
def test_namespaced_habtm
magazine = Publisher::Magazine.create
article = Publisher::Article.create
magazine.articles << article
magazine.save
assert_includes magazine.articles, article
end
end

View file

@ -0,0 +1,2 @@
module Publisher
end

View file

@ -0,0 +1,3 @@
class Publisher::Article < ActiveRecord::Base
has_and_belongs_to_many :magazines
end

View file

@ -0,0 +1,3 @@
class Publisher::Magazine < ActiveRecord::Base
has_and_belongs_to_many :articles
end

View file

@ -62,6 +62,14 @@ ActiveRecord::Schema.define do
t.string :name
end
create_table :articles, force: true do |t|
end
create_table :articles_magazines, force: true do |t|
t.references :article
t.references :magazine
end
create_table :audit_logs, force: true do |t|
t.column :message, :string, null: false
t.column :developer_id, :integer, null: false
@ -385,6 +393,9 @@ ActiveRecord::Schema.define do
t.column :custom_lock_version, :integer
end
create_table :magazines, force: true do |t|
end
create_table :mateys, id: false, force: true do |t|
t.column :pirate_id, :integer
t.column :target_id, :integer