Merge pull request #51941 from Liamjen/allow_unscope_cte
Allow unscoping ActiveRecord Query CTEs
This commit is contained in:
commit
f6666de591
@ -751,7 +751,7 @@ def reorder!(*args) # :nodoc:
|
||||
VALID_UNSCOPING_VALUES = Set.new([:where, :select, :group, :order, :lock,
|
||||
:limit, :offset, :joins, :left_outer_joins, :annotate,
|
||||
:includes, :eager_load, :preload, :from, :readonly,
|
||||
:having, :optimizer_hints])
|
||||
:having, :optimizer_hints, :with])
|
||||
|
||||
# Removes an unwanted relation that is already defined on a chain of relations.
|
||||
# This is useful when passing around chains of relations and would like to
|
||||
|
@ -114,6 +114,15 @@ def test_raises_when_using_block
|
||||
Post.with(attributes_for_inspect: :id) { }
|
||||
end
|
||||
end
|
||||
|
||||
def test_unscoping
|
||||
relation = Post.with(posts_with_comments: Post.where("legacy_comments_count > 0"))
|
||||
|
||||
assert_equal true, relation.values[:with].flat_map(&:keys).include?(:posts_with_comments)
|
||||
relation = relation.unscope(:with)
|
||||
assert_nil relation.values[:with]
|
||||
assert_equal Post.count, relation.count
|
||||
end
|
||||
else
|
||||
def test_common_table_expressions_are_unsupported
|
||||
assert_raises ActiveRecord::StatementInvalid do
|
||||
|
Loading…
Reference in New Issue
Block a user