Add party validation and inverse to GridObject associations

This commit is contained in:
Justin Edmund 2023-01-08 21:49:25 -08:00
parent fa2962ae1c
commit b6e8dd93b1
3 changed files with 13 additions and 3 deletions

View file

@ -1,7 +1,10 @@
# frozen_string_literal: true
class GridCharacter < ApplicationRecord
belongs_to :party
belongs_to :party,
counter_cache: :weapons_count,
inverse_of: :characters
validates_presence_of :party
validate :awakening_level, on: :update
validate :transcendence, on: :update

View file

@ -1,7 +1,10 @@
# frozen_string_literal: true
class GridSummon < ApplicationRecord
belongs_to :party
belongs_to :party,
counter_cache: :weapons_count,
inverse_of: :summons
validates_presence_of :party
def summon
Summon.find(summon_id)

View file

@ -2,7 +2,9 @@
class GridWeapon < ApplicationRecord
belongs_to :party,
counter_cache: :weapons_count
counter_cache: :weapons_count,
inverse_of: :weapons
validates_presence_of :party
belongs_to :weapon_key1, class_name: 'WeaponKey', foreign_key: :weapon_key1_id, optional: true
belongs_to :weapon_key2, class_name: 'WeaponKey', foreign_key: :weapon_key2_id, optional: true
@ -29,6 +31,8 @@ class GridWeapon < ApplicationRecord
return unless weapon.limit
party.weapons.find do |party_weapon|
return unless party_weapon.id
id_match = weapon.id == party_weapon.id
series_match = weapon.series == party_weapon.weapon.series
both_opus_or_draconic = weapon.opus_or_draconic? && party_weapon.weapon.opus_or_draconic?