Files
fizzy/app/models/collection.rb
T
Jason Zimdars 117d5c6e59 Accounts always start with a "Cards" collection
- Deleting the last collection, immediately creates a new "Cards" collection
2025-05-02 17:35:24 +02:00

21 lines
540 B
Ruby

class Collection < ApplicationRecord
include AutoClosing, Accessible, Broadcastable, 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
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