Files
fizzy/app/models/collection.rb
T
Jorge Manrubia db86d17880 Refactor to introduce an entropy model
Instead of keeping two tracks of similar logic (auto-reconsider / auto-close).
2025-06-04 14:40:02 +02:00

22 lines
658 B
Ruby

class Collection < ApplicationRecord
include AutoClosing, Accessible, Broadcastable, Entropic, Filterable, Workflowing
belongs_to :creator, class_name: "User", default: -> { Current.user }
has_many :cards, dependent: :destroy
has_many :tags, -> { distinct }, through: :cards
has_many :events
has_one :entropy_configuration, class_name: "Entropy::Configuration", as: :container, dependent: :destroy
scope :alphabetically, -> { order("lower(name)") }
after_destroy_commit :ensure_default_collection
private
def ensure_default_collection
if Collection.count.zero?
Collection.create!(name: "Cards")
end
end
end