Manuel Bustillo
91bbae1c63
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 59s
Add copyright notice / copyright_notice (pull_request) Successful in 2m21s
Run unit tests / unit_tests (pull_request) Successful in 3m2s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 25m17s
46 lines
1.2 KiB
Ruby
46 lines
1.2 KiB
Ruby
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
|
|
|
# frozen_string_literal: true
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: group_affinities
|
|
#
|
|
# id :bigint not null, primary key
|
|
# discomfort :float not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# group_a_id :uuid not null
|
|
# group_b_id :uuid not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_group_affinities_on_group_a_id (group_a_id)
|
|
# index_group_affinities_on_group_b_id (group_b_id)
|
|
# uindex_group_pair (LEAST(group_a_id, group_b_id), GREATEST(group_a_id, group_b_id)) UNIQUE
|
|
#
|
|
# Foreign Keys
|
|
#
|
|
# fk_rails_... (group_a_id => groups.id)
|
|
# fk_rails_... (group_b_id => groups.id)
|
|
#
|
|
class GroupAffinity < ApplicationRecord
|
|
NEUTRAL = 1
|
|
MIN_DISCOMFORT = 0
|
|
MAX_DISCOMFORT = 2
|
|
|
|
belongs_to :group_a, class_name: 'Group'
|
|
belongs_to :group_b, class_name: 'Group'
|
|
|
|
validates :discomfort,
|
|
numericality: { greater_than_or_equal_to: MIN_DISCOMFORT, less_than_or_equal_to: MAX_DISCOMFORT }
|
|
|
|
def another_group(group)
|
|
return nil if group != group_a && group != group_b
|
|
|
|
group == group_a ? group_b : group_a
|
|
end
|
|
end
|