WIP: targets forms
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user