Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Start with WHERE-Walker

Klaus Zanders4612e41659e3
diff --git a/app/models/journable/historic_active_record_relation.rb b/app/models/journable/historic_active_record_relation.rb
index 4eaa4ee9317..cbfdaf152c8 100644
--- a/app/models/journable/historic_active_record_relation.rb
+++ b/app/models/journable/historic_active_record_relation.rb
@@ -115,7 +115,8 @@ class Journable::HistoricActiveRecordRelation < ActiveRecord::Relation
# Based on the previous modifications, build the algebra object.
arel = relation.call_original_build_arel(aliases)
arel = modify_order_clauses(arel)
- modify_joins(arel)
+ arel = modify_joins(arel)
+ modify_where_clauses(arel)
end
def call_original_build_arel(aliases = nil)
@@ -364,6 +365,42 @@ class Journable::HistoricActiveRecordRelation < ActiveRecord::Relation
arel
end
+ def modify_where_clauses(arel)
+ arel.instance_variable_get(:@ast).instance_variable_get(:@cores).each do |core|
+ core.instance_variable_get(:@wheres).each do |where_clause|
+ modify_conditions(where_clause)
+ end
+ end
+
+ arel
+ end
+
+ def modify_conditions(node)
+ puts "#{node.class}: #{node.respond_to?(:to_sql) ? node.to_sql : node.inspect}"
+
+ if node.kind_of? Arel::TreeManager
+ node.instance_variable_get(:@ast).instance_variable_get(:@cores).each do |core|
+ modify_conditions(core)
+ end
+ elsif node.kind_of? Arel::Nodes::SelectCore
+ source = node.instance_variable_get(:@source)
+ modify_conditions(source.left)
+ source.right.each do |src|
+ modify_conditions(src)
+ end
+ elsif node.kind_of?(Arel::Nodes::On)
+ [node.expr.left, node.expr.right].each { |child| modify_conditions(child) }
+ elsif node.kind_of? Arel::Nodes::Casted
+ puts "Casted: #{node.value}"
+ elsif node.kind_of?(Arel::Attributes::Attribute)
+ puts "#{node.relation&.name}.#{node.name}"
+ elsif node.kind_of? Arel::Nodes::NodeExpression
+ [node.left, node.right].each { |child| modify_conditions(child) }
+ end
+
+ node
+ end
+
# Replace table names in sql strings, e.g.
#
# "work_package.id" => "journals.journable_id"