Partial refresh of Measurements#new form

This commit is contained in:
2025-02-18 18:27:47 +01:00
parent c48bf290fd
commit 8401424efa
6 changed files with 65 additions and 55 deletions

View File

@@ -3,8 +3,8 @@ class Quantity < ApplicationRecord
belongs_to :user, optional: true
belongs_to :parent, optional: true, class_name: "Quantity"
has_many :subquantities, class_name: "Quantity", inverse_of: :parent,
dependent: :restrict_with_error
has_many :subquantities, ->{ order(:name) }, class_name: "Quantity",
inverse_of: :parent, dependent: :restrict_with_error
validate if: ->{ parent.present? } do
errors.add(:parent, :user_mismatch) unless user_id == parent.user_id
@@ -168,8 +168,10 @@ class Quantity < ApplicationRecord
user.quantities.with_ancestors(progeny.id).exists?(id)
end
def fullname
def self.full_names!(of)
self['fullname'] ||
user.quantities.with_ancestors(id).order(:depth).map(&:name).join(' → ')
end
scope :with_full_name, ->{
}
end