Use join instead of subquery on Label.unprioritized scope

parent 4c924107
...@@ -39,7 +39,14 @@ class Label < ActiveRecord::Base ...@@ -39,7 +39,14 @@ class Label < ActiveRecord::Base
end end
def self.unprioritized(project) def self.unprioritized(project)
where.not(id: prioritized(project).select(:id)) labels = Label.arel_table
priorities = LabelPriority.arel_table
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin).
on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))).
join_sources
joins(label_priorities).where(priorities[:priority].eq(nil))
end end
def self.left_join_priorities def self.left_join_priorities
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment