forked from fixin.me/fixin.me
Patch ActiveRecord with PR 54658
This commit is contained in:
parent
8401424efa
commit
4c867daabb
@ -11,4 +11,15 @@ end
|
||||
ActiveSupport.on_load :active_record do
|
||||
ActiveModel::Validations::NumericalityValidator
|
||||
.prepend CoreExt::ActiveModel::Validations::NumericalityValidatesPrecisionAndScale
|
||||
|
||||
# Temporary patch for https://github.com/rails/rails/pull/54658
|
||||
Arel::TreeManager::StatementMethods
|
||||
.prepend CoreExt::Arel::TreeManager::StatementMethodsCteUpdateAndDelete
|
||||
Arel::Nodes::DeleteStatement
|
||||
.prepend CoreExt::Arel::Nodes::DeleteStatementCteUpdateAndDelete
|
||||
Arel::Nodes::UpdateStatement
|
||||
.prepend CoreExt::Arel::Nodes::UpdateStatementCteUpdateAndDelete
|
||||
Arel::Visitors::ToSql.prepend CoreExt::Arel::Visitors::ToSqlCteUpdateAndDelete
|
||||
Arel::Crud.prepend CoreExt::Arel::CrudCteUpdateAndDelete
|
||||
Arel::SelectManager.prepend CoreExt::Arel::SelectManagerCteUpdateAndDelete
|
||||
end
|
||||
|
@ -0,0 +1,3 @@
|
||||
module CoreExt::ActiveRecord::Relation::UpdateAndDeleteCteSupport
|
||||
INVALID_METHODS_FOR_UPDATE_AND_DELETE_ALL = [:distinct]
|
||||
end
|
11
lib/core_ext/arel/crud_cte_update_and_delete.rb
Normal file
11
lib/core_ext/arel/crud_cte_update_and_delete.rb
Normal 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
|
@ -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
|
@ -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
|
@ -0,0 +1,5 @@
|
||||
module CoreExt::Arel::SelectManagerCteUpdateAndDelete
|
||||
def subqueries
|
||||
@ast.with
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
module CoreExt::Arel::TreeManager::StatementMethodsCteUpdateAndDelete
|
||||
def with=(expr)
|
||||
@ast.with = expr
|
||||
self
|
||||
end
|
||||
end
|
19
lib/core_ext/arel/visitors/to_sql_cte_update_and_delete.rb
Normal file
19
lib/core_ext/arel/visitors/to_sql_cte_update_and_delete.rb
Normal 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
|
Loading…
x
Reference in New Issue
Block a user