Redo simulations lifecycle #222
| @ -19,4 +19,6 @@ class Wedding < ApplicationRecord | |||||||
|   SLUG_REGEX = /[a-z\d-]+/ |   SLUG_REGEX = /[a-z\d-]+/ | ||||||
| 
 | 
 | ||||||
|   validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ } |   validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ } | ||||||
|  | 
 | ||||||
|  |   has_many :guests, dependent: :delete_all | ||||||
| end | end | ||||||
|  | |||||||
| @ -6,7 +6,13 @@ require_relative '../../extensions/tree_node_extension' | |||||||
| 
 | 
 | ||||||
| module Tables | module Tables | ||||||
|   class Distribution |   class Distribution | ||||||
|     attr_accessor :tables, :min_per_table, :max_per_table |     class << self | ||||||
|  |       def digest(wedding) | ||||||
|  |         Digest::UUID.uuid_v5(wedding.id, wedding.guests.potential.order(:id).pluck(:id).join) | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     attr_accessor :tables, :min_per_table, :max_per_table, :hierarchy | ||||||
| 
 | 
 | ||||||
|     def initialize(min_per_table:, max_per_table:) |     def initialize(min_per_table:, max_per_table:) | ||||||
|       @min_per_table = min_per_table |       @min_per_table = min_per_table | ||||||
| @ -54,7 +60,10 @@ module Tables | |||||||
| 
 | 
 | ||||||
|         Seat.insert_all!(records_to_store) |         Seat.insert_all!(records_to_store) | ||||||
| 
 | 
 | ||||||
|         arrangement.update!(discomfort:) |         arrangement.update!( | ||||||
|  |           discomfort:, | ||||||
|  |           guests_digest: self.class.digest(tables.first.first.wedding) | ||||||
|  |         ) | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user