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

prevent scope being applied in subquery

ulferts9c077a5962c4
diff --git a/app/models/work_packages/scopes/relatable.rb b/app/models/work_packages/scopes/relatable.rb
index d78d1cdc1c7..3d9d1eddaa0 100644
--- a/app/models/work_packages/scopes/relatable.rb
+++ b/app/models/work_packages/scopes/relatable.rb
@@ -202,11 +202,11 @@ module WorkPackages::Scopes
if relation_type == Relation::TYPE_RELATES
# Bypassing the recursive query in this case as only children and parent needs to be excluded.
# Using this more complicated statement since
- # where.not(parent:id: work_package.id)
+ # where.not(parent_id: work_package.id)
# will lead to
# "parent_id != 123" which excludes
# work packages having parent_id NULL.
- where.not(id: where(id: work_package.parent_id).or(where(parent_id: work_package.id)).select(:id))
+ where.not(id: unscoped.where(id: work_package.parent_id).or(unscoped.where(parent_id: work_package.id)).select(:id))
else
sql = <<~SQL.squish
WITH