55 lines
1.2 KiB
Ruby
Raw Normal View History

2024-10-27 21:42:45 +00:00
# Copyright (C) 2024 Manuel Bustillo
# == Schema Information
#
# Table name: guests
#
# id :uuid not null, primary key
# name :string
# phone :string
# status :integer default("considered")
# created_at :datetime not null
# updated_at :datetime not null
# group_id :uuid
2024-11-30 20:04:17 +01:00
# wedding_id :uuid not null
#
# Indexes
#
2024-11-30 20:04:17 +01:00
# index_guests_on_group_id (group_id)
# index_guests_on_wedding_id (wedding_id)
#
# Foreign Keys
#
# fk_rails_... (group_id => groups.id)
2024-11-30 20:04:17 +01:00
# fk_rails_... (wedding_id => weddings.id)
#
2024-07-11 20:08:26 +02:00
class Guest < ApplicationRecord
2024-11-30 20:04:17 +01:00
acts_as_tenant :wedding
belongs_to :group
2024-08-11 19:24:24 +02:00
enum :status, {
2024-08-11 19:24:24 +02:00
considered: 0,
invited: 10,
confirmed: 20,
2024-10-27 19:25:24 +01:00
declined: 30,
tentative: 40
}, validate: true
validates :name, presence: true
2024-08-11 19:24:24 +02:00
scope :potential, -> { where.not(status: %i[declined considered]) }
2024-11-17 17:07:29 +01:00
after_save :recalculate_simulations, if: :saved_change_to_status?
after_destroy :recalculate_simulations
2024-11-17 17:07:29 +01:00
2024-11-17 18:24:43 +01:00
has_many :seats, dependent: :delete_all
2024-11-17 17:07:29 +01:00
private
def recalculate_simulations
TablesArrangement.delete_all
ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new(wedding_id) })
2024-11-17 17:07:29 +01:00
end
2024-07-11 20:08:26 +02:00
end