Patch ActiveRecord with PR 54658

This commit is contained in:
2025-03-22 14:14:42 +01:00
parent 8401424efa
commit 4c867daabb
8 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
module CoreExt::ActiveRecord::Relation::UpdateAndDeleteCteSupport
INVALID_METHODS_FOR_UPDATE_AND_DELETE_ALL = [:distinct]
end

View File

@@ -0,0 +1,11 @@
module CoreExt::Arel::CrudCteUpdateAndDelete
def compile_update(...)
um = super
um.with = subqueries
end
def compile_delete(...)
dm = super
dm.with = subqueries
end
end

View File

@@ -0,0 +1,16 @@
module CoreExt::Arel::Nodes::DeleteStatementCteUpdateAndDelete
attr_accessor :with
def initialize(...)
super
@with = nil
end
def hash
[self.class, @relation, @wheres, @orders, @limit, @offset, @key, @with].hash
end
def eql?(other)
eql?(other) && self.with == other.with
end
end

View File

@@ -0,0 +1,16 @@
module CoreExt::Arel::Nodes::UpdateStatementCteUpdateAndDelete
attr_accessor :with
def initialize(...)
super
@with = nil
end
def hash
[self.class, @relation, @wheres, @orders, @limit, @offset, @key, @with].hash
end
def eql?(other)
eql?(other) && self.with == other.with
end
end

View File

@@ -0,0 +1,5 @@
module CoreExt::Arel::SelectManagerCteUpdateAndDelete
def subqueries
@ast.with
end
end

View File

@@ -0,0 +1,6 @@
module CoreExt::Arel::TreeManager::StatementMethodsCteUpdateAndDelete
def with=(expr)
@ast.with = expr
self
end
end

View File

@@ -0,0 +1,19 @@
module CoreExt::Arel::Visitors::ToSqlCteUpdateAndDelete
def visit_Arel_Nodes_DeleteStatement(o, collector)
if o.with
collector = visit o.with, collector
collector << " "
end
super
end
def visit_Arel_Nodes_UpdateStatement(o, collector)
if o.with
collector = visit o.with, collector
collector << " "
end
super
end
end