Set constraints on Readouts.user_id foreign key

Add Measurements table
This commit is contained in:
2026-05-05 20:33:21 +02:00
parent 4a36ffc8bf
commit d3a34233b9
10 changed files with 107 additions and 22 deletions

View File

@@ -6,6 +6,7 @@ class Quantity < ApplicationRecord
belongs_to :parent, optional: true, class_name: "Quantity"
has_many :subquantities, ->{ order(:name) }, class_name: "Quantity",
inverse_of: :parent, dependent: :restrict_with_error
has_many :readouts, dependent: :restrict_with_error
validate if: ->{ parent.present? } do
errors.add(:parent, :user_mismatch) unless user_id == parent.user_id