rename from sibling_columns to surroundings
This commit is contained in:
@@ -6,10 +6,5 @@ class Column < ApplicationRecord
|
|||||||
has_many :cards, dependent: :nullify
|
has_many :cards, dependent: :nullify
|
||||||
|
|
||||||
after_save_commit -> { cards.touch_all }, if: -> { saved_change_to_name? || saved_change_to_color? }
|
after_save_commit -> { cards.touch_all }, if: -> { saved_change_to_name? || saved_change_to_color? }
|
||||||
after_create_commit -> { sibling_columns.touch_all }
|
after_destroy_commit -> { board.cards.touch_all }
|
||||||
after_destroy_commit -> { board.cards.touch_all; sibling_columns.touch_all }
|
|
||||||
|
|
||||||
def sibling_columns
|
|
||||||
board.columns.where.not(id:).sorted
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ module Column::Positioned
|
|||||||
scope :sorted, -> { order(position: :asc) }
|
scope :sorted, -> { order(position: :asc) }
|
||||||
|
|
||||||
before_create :set_position
|
before_create :set_position
|
||||||
|
after_create_commit -> { surroundings.touch_all }
|
||||||
|
after_destroy_commit -> { surroundings.touch_all }
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_left
|
def move_left
|
||||||
@@ -31,6 +33,10 @@ module Column::Positioned
|
|||||||
right_column.nil?
|
right_column.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def surroundings
|
||||||
|
board.columns.where(id: [ left_column&.id, right_column&.id ].compact)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def set_position
|
def set_position
|
||||||
max_position = board.columns.maximum(:position) || 0
|
max_position = board.columns.maximum(:position) || 0
|
||||||
|
|||||||
Reference in New Issue
Block a user