1
0

WIP: targets forms

This commit is contained in:
cryptogopher
2021-02-21 11:33:30 +01:00
parent 9e3dc24a14
commit ea308a1e4a
7 changed files with 34 additions and 31 deletions

View File

@@ -5,7 +5,7 @@ class QuantityValue < ActiveRecord::Base
# to allow for accessing registry item without knowing QuantityValue (subitem)
# type, e.g. qv.registry.completed_at
belongs_to :registry, polymorphic: true
belongs_to :quantity, required: true
belongs_to :quantity, -> { where(domain: DOMAIN) }, required: true
belongs_to :unit, required: true
# Uniqueness is checked exclusively on the other end of association level.

View File

@@ -1,6 +1,7 @@
class Target < ActiveRecord::Base
belongs_to :goal, inverse_of: :targets, required: true
belongs_to :quantity, inverse_of: :targets, required: true
belongs_to :quantity, -> { where.not(domain: :target) }, inverse_of: :targets,
required: true
belongs_to :item, polymorphic: true, inverse_of: :targets
has_many :thresholds, -> { joins(:quantity).order(:lft) },
as: :registry, inverse_of: :target, dependent: :destroy, validate: true

View File

@@ -1,4 +1,6 @@
class Threshold < QuantityValue
DOMAIN = :target
# Need to specify polymorphic association so :registry_type gets written (see
# QuantityValue for explanation why it's needed)
belongs_to :target, inverse_of: :thresholds, polymorphic: true, required: true,