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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
at_timestamp: handle case where "work_packages.id IN sub query"
Sebastian Fiedlschuster47c45b6a9f8a
diff --git a/app/models/journable/historic_active_record_relation.rb b/app/models/journable/historic_active_record_relation.rbindex 64b6a891bb8..6752d19865a 100644--- a/app/models/journable/historic_active_record_relation.rb+++ b/app/models/journable/historic_active_record_relation.rb@@ -140,22 +140,16 @@ class Journable::HistoricActiveRecordRelation < ActiveRecord::RelationArel::Nodes::LessThanOrEqual,Arel::Nodes::GreaterThan,Arel::Nodes::GreaterThanOrEqual- if predicate.left.relation == arel_table- if predicate.right.respond_to? :name- case predicate.right.name- when "id"- predicate.right.instance_variable_set(:@name, "journable_id")- predicate.left.name = "journable_id"- predicate.left.relation = Journal.arel_table- when "updated_at"- predicate.right.instance_variable_set(:@name, "created_at")- predicate.left.name = "created_at"- predicate.left.relation = Journal.arel_table- when "created_at"- predicate.left = Arel::Nodes::SqlLiteral.new("\"journables\".\"created_at\"")- else- predicate.left.relation = journal_class.arel_table- end+ if predicate.left.relation == arel_table or predicate.left.relation == journal_class.arel_table+ case predicate.left.name+ when "id"+ predicate.left.name = "journable_id"+ predicate.left.relation = Journal.arel_table+ when "updated_at"+ predicate.left.name = "created_at"+ predicate.left.relation = Journal.arel_table+ when "created_at"+ predicate.left = Arel::Nodes::SqlLiteral.new("\"journables\".\"created_at\"")elsepredicate.left.relation = journal_class.arel_tableenddiff --git a/spec/models/journable/historic_active_record_relation_spec.rb b/spec/models/journable/historic_active_record_relation_spec.rbindex 5c735065733..44f0696c30c 100644--- a/spec/models/journable/historic_active_record_relation_spec.rb+++ b/spec/models/journable/historic_active_record_relation_spec.rb@@ -115,6 +115,38 @@ describe Journable::HistoricActiveRecordRelation doendend+ describe "id in array (Arel::Nodes::HomogeneousIn)" do+ let(:relation) { WorkPackage.where(id: [work_package.id, 999, 9999]) }++ describe "#to_sql" do+ it "transforms the expression to query the correct table" do+ expect(subject.to_sql).to include "\"journals\".\"journable_id\" IN (#{work_package.id}, 999, 9999)"+ end+ end++ describe "#to_a" do+ it "returns the requested work package" do+ expect(subject.to_a).to include work_package+ end+ end+ end++ describe "id in subquery (Arel::Nodes::In)" do+ let(:relation) { WorkPackage.where(id: WorkPackage.where(id: [work_package.id, 999, 9999])) }++ describe "#to_sql" do+ it "transforms the expression to query the correct table" do+ expect(subject.to_sql).to include "\"journals\".\"journable_id\" IN (SELECT \"work_packages\".\"id\""+ end+ end++ describe "#to_a" do+ it "returns the requested work package" do+ expect(subject.to_a).to include work_package+ end+ end+ end+describe "sql string (as used by Query#statement)" dolet(:relation) { WorkPackage.where("(work_packages.description ILIKE '%been on Wednesday%')") }