未验证 提交 afb65390 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #39967 from kamipo/fix_or_with_sti_relation

Avoid implicit `create_with` for `StiClass.all`
......@@ -320,7 +320,6 @@ def relation
if finder_needs_type_condition? && !ignore_default_scope?
relation.where!(type_condition)
relation.create_with!(inheritance_column.to_s => sti_name)
else
relation
end
......
......@@ -686,6 +686,7 @@ def where_values_hash(relation_table_name = klass.table_name)
def scope_for_create
hash = where_values_hash
hash.delete(klass.inheritance_column) if klass.finder_needs_type_condition?
create_with_value.each { |k, v| hash[k.to_s] = v } unless create_with_value.empty?
hash
end
......
......@@ -111,6 +111,11 @@ def test_or_inside_named_scope
assert_equal expected, Post.order(id: :desc).typographically_interesting
end
def test_or_with_sti_relation
expected = Post.where("id = 1 or id = 2").sort_by(&:id)
assert_equal expected, Post.where(id: 1).or(SpecialPost.all).sort_by(&:id)
end
def test_or_on_loaded_relation
expected = Post.where("id = 1 or id = 2").to_a
p = Post.where("id = 1")
......
......@@ -356,6 +356,10 @@ def predicate_builder
Post.predicate_builder
end
def finder_needs_type_condition?
false
end
def base_class?
true
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册