Add party validation and inverse to GridObject associations
This commit is contained in:
parent
fa2962ae1c
commit
b6e8dd93b1
3 changed files with 13 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
Loading…
Reference in a new issue