Use join instead of subquery on Label.unprioritized scope

This commit is contained in:
Douglas Barbosa Alexandre 2016-10-18 04:00:33 -02:00
parent 4c9241075d
commit f99744d00d

View file

@ -39,7 +39,14 @@ class Label < ActiveRecord::Base
end
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
def self.left_join_priorities