提交 8f6e5986 编写于 作者: K Kassio Borges

Fix how to compute class name on habtm namespaced.

Thank's for @laurocaetano for the help with tests. 😃

Fixes #14709
上级 c6c16423
* Fix how to calculate associated class name when using `habtm` namespaced.
Fixes #14709.
*Kassio Borges*
* `change_column_default` allows `[]` as argument to `change_column_default`. * `change_column_default` allows `[]` as argument to `change_column_default`.
Fixes #11586. Fixes #11586.
......
...@@ -23,7 +23,11 @@ def self.build(lhs_class, name, options) ...@@ -23,7 +23,11 @@ def self.build(lhs_class, name, options)
KnownTable.new options[:join_table].to_s KnownTable.new options[:join_table].to_s
else else
class_name = options.fetch(:class_name) { 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 KnownClass.new lhs_class, class_name
end end
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
require 'models/country' require 'models/country'
require 'models/treaty' require 'models/treaty'
require 'models/vertex' require 'models/vertex'
require 'models/publisher'
require 'models/publisher/article'
require 'models/publisher/magazine'
require 'active_support/core_ext/string/conversions' require 'active_support/core_ext/string/conversions'
class ProjectWithAfterCreateHook < ActiveRecord::Base class ProjectWithAfterCreateHook < ActiveRecord::Base
...@@ -848,4 +851,13 @@ def test_association_with_validate_false_does_not_run_associated_validation_call ...@@ -848,4 +851,13 @@ def test_association_with_validate_false_does_not_run_associated_validation_call
def test_custom_join_table def test_custom_join_table
assert_equal 'edges', Vertex.reflect_on_association(:sources).join_table assert_equal 'edges', Vertex.reflect_on_association(:sources).join_table
end 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 end
class Publisher::Article < ActiveRecord::Base
has_and_belongs_to_many :magazines
end
class Publisher::Magazine < ActiveRecord::Base
has_and_belongs_to_many :articles
end
...@@ -62,6 +62,14 @@ def create_table(*args, &block) ...@@ -62,6 +62,14 @@ def create_table(*args, &block)
t.string :name t.string :name
end 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| create_table :audit_logs, force: true do |t|
t.column :message, :string, null: false t.column :message, :string, null: false
t.column :developer_id, :integer, null: false t.column :developer_id, :integer, null: false
...@@ -385,6 +393,9 @@ def create_table(*args, &block) ...@@ -385,6 +393,9 @@ def create_table(*args, &block)
t.column :custom_lock_version, :integer t.column :custom_lock_version, :integer
end end
create_table :magazines, force: true do |t|
end
create_table :mateys, id: false, force: true do |t| create_table :mateys, id: false, force: true do |t|
t.column :pirate_id, :integer t.column :pirate_id, :integer
t.column :target_id, :integer t.column :target_id, :integer
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册