Files
fizzy/app/models/collection.rb
T
2025-04-09 14:50:58 +02:00

22 lines
582 B
Ruby

class Collection < ApplicationRecord
include Accessible, Broadcastable, Filterable
belongs_to :account
belongs_to :creator, class_name: "User", default: -> { Current.user }
belongs_to :workflow, optional: true
has_many :cards, dependent: :destroy
has_many :tags, -> { distinct }, through: :cards
validates_presence_of :name
after_save :update_cards_workflow, if: :saved_change_to_workflow_id?
scope :alphabetically, -> { order("lower(name)") }
private
def update_cards_workflow
cards.update_all(stage_id: workflow&.stages&.first&.id)
end
end