diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-15 00:32:44 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-19 19:58:27 +0300 |
commit | 67314e95ae836365fa1989439a6379aac781a0b4 (patch) | |
tree | 7f364243353cbc8ac311fc54119ad64ec41452b0 /app/models/label.rb | |
parent | 297892011330ecdd2fa7cbe47fbc6fd4f3b62171 (diff) |
Add support to group labels prioritization on project level
Diffstat (limited to 'app/models/label.rb')
-rw-r--r-- | app/models/label.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/app/models/label.rb b/app/models/label.rb index 3ce4e253035..ea11d9d7864 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -32,12 +32,14 @@ class Label < ActiveRecord::Base scope :templates, -> { where(template: true) } scope :with_title, ->(title) { where(title: title) } - def self.prioritized - where.not(priority: nil).reorder(:priority, :title) + def self.prioritized(project) + joins(:priorities) + .where(label_priorities: { project_id: project }) + .reorder('label_priorities.priority ASC, labels.title ASC') end - def self.unprioritized - where(priority: nil) + def self.unprioritized(project) + where.not(id: prioritized(project).select(:id)) end alias_attribute :name, :title |