提交 33fcdfff 编写于 作者: C Carlos Antonio da Silva

Merge pull request #14992 from fredwu/habtm_relation_size_calculation_fix

Habtm relation size calculation fix. Fixes #14913, Fixes #14914.
* Fixed HABTM's CollectionAssociation size calculation.
HABTM should fall back to using the normal CollectionAssociation's size
calculation if the collection is not cached or loaded.
Fixes #14913 and #14914.
*Fred Wu*
* Return a non zero status when running `rake db:migrate:status` and migration table does * Return a non zero status when running `rake db:migrate:status` and migration table does
not exist. not exist.
......
...@@ -23,7 +23,7 @@ def size ...@@ -23,7 +23,7 @@ def size
elsif loaded? elsif loaded?
target.size target.size
else else
count super
end end
end end
......
...@@ -217,6 +217,24 @@ def test_habtm_unique_order_preserved ...@@ -217,6 +217,24 @@ def test_habtm_unique_order_preserved
assert_equal developers(:poor_jamis, :jamis, :david), projects(:active_record).developers assert_equal developers(:poor_jamis, :jamis, :david), projects(:active_record).developers
end end
def test_habtm_collection_size_from_build
devel = Developer.create("name" => "Fred Wu")
devel.projects << Project.create("name" => "Grimetime")
devel.projects.build
assert_equal 2, devel.projects.size
end
def test_habtm_collection_size_from_params
devel = Developer.new({
projects_attributes: {
'0' => {}
}
})
assert_equal 1, devel.projects.size
end
def test_build def test_build
devel = Developer.find(1) devel = Developer.find(1)
proj = assert_no_queries { devel.projects.build("name" => "Projekt") } proj = assert_no_queries { devel.projects.build("name" => "Projekt") }
......
...@@ -13,6 +13,8 @@ def find_most_recent ...@@ -13,6 +13,8 @@ def find_most_recent
end end
end end
accepts_nested_attributes_for :projects
has_and_belongs_to_many :projects_extended_by_name, has_and_belongs_to_many :projects_extended_by_name,
-> { extending(DeveloperProjectsAssociationExtension) }, -> { extending(DeveloperProjectsAssociationExtension) },
:class_name => "Project", :class_name => "Project",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册