Commit 852d4319 authored by charlieablett's avatar charlieablett

Move order lambda to list scope

- apply ordering to both list scopes in `Board`
- remove extra preloads
parent 3d6297f8
...@@ -4,8 +4,8 @@ class Board < ApplicationRecord ...@@ -4,8 +4,8 @@ class Board < ApplicationRecord
belongs_to :group belongs_to :group
belongs_to :project belongs_to :project
has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent has_many :lists, -> { ordered }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :destroyable_lists, -> { lists.destroyable }, class_name: "List" has_many :destroyable_lists, -> { destroyable.ordered }, class_name: "List"
validates :project, presence: true, if: :project_needed? validates :project, presence: true, if: :project_needed?
validates :group, presence: true, unless: :project validates :group, presence: true, unless: :project
......
...@@ -18,6 +18,7 @@ class List < ApplicationRecord ...@@ -18,6 +18,7 @@ class List < ApplicationRecord
scope :destroyable, -> { where(list_type: list_types.slice(*destroyable_types).values) } scope :destroyable, -> { where(list_type: list_types.slice(*destroyable_types).values) }
scope :movable, -> { where(list_type: list_types.slice(*movable_types).values) } scope :movable, -> { where(list_type: list_types.slice(*movable_types).values) }
scope :preload_associations, -> { preload(:board, :label) } scope :preload_associations, -> { preload(:board, :label) }
scope :ordered, -> { order(:list_type, :position) }
class << self class << self
def destroyable_types def destroyable_types
......
...@@ -23,7 +23,7 @@ module EE ...@@ -23,7 +23,7 @@ module EE
validates :name, presence: true validates :name, presence: true
scope :with_associations, -> { preload(:destroyable_lists, :milestone, :board_labels, :labels, :assignee) } scope :with_associations, -> { preload(:destroyable_lists, :labels, :assignee) }
end end
override :scoped? override :scoped?
......
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