forked from fixin.me/fixin.me
Set constraints on Readouts.user_id foreign key
Add Measurements table
This commit is contained in:
@@ -6,7 +6,7 @@ class ReadoutsController < ApplicationController
|
||||
def new
|
||||
@quantities -= @prev_quantities
|
||||
# TODO: raise ParameterInvalid if new_quantities.empty?
|
||||
@readouts = current_user.readouts.build(@quantities.map { |q| {quantity: q} })
|
||||
@readouts = @quantities.map { |q| q.readouts.build }
|
||||
|
||||
@user_units = current_user.units.ordered
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,4 +4,6 @@ class Readout < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :quantity
|
||||
belongs_to :unit
|
||||
|
||||
# TODO: validate quantity.user_id == unit.user_id != NULL
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user