1
0

List binding goal targets

This commit is contained in:
cryptogopher
2021-02-21 19:41:24 +01:00
parent 7f87b3bc84
commit 09e27eb754
18 changed files with 26 additions and 20 deletions

View File

@@ -14,7 +14,7 @@ class Goal < ActiveRecord::Base
after_initialize do
if new_record?
self.is_binding = false if self.is_binding.nil?
self.targets.new if self.targets.empty?
self.targets.new if !self.is_binding && self.targets.empty?
end
end

View File

@@ -5,7 +5,10 @@ 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, ->(qv) { where(domain: qv.class::DOMAIN) }, required: true
belongs_to :quantity, required: true
validate do
errors.add(:quantity, :domain_mismatch) unless self.class::DOMAIN == quantity.domain
end
belongs_to :unit, required: true
# Uniqueness is checked exclusively on the other end of association level.