1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/models/quantity.rb
cryptogopher 3ebc2f58d0 Finished CSV import
Fixed problem with excessive validation
2019-09-22 20:26:07 +02:00

17 lines
455 B
Ruby

class Quantity < ActiveRecord::Base
enum domain: {
diet: 0,
measurement: 1,
exercise: 2
}
acts_as_nested_set dependent: :nullify, scope: :project
belongs_to :project, required: false
validates :name, presence: true, uniqueness: {scope: :project_id}
validates :domain, inclusion: {in: domains.keys}
validate if: -> { parent.present? } do
errors.add(:parent, :parent_domain_mismatch) unless domain == parent.domain
end
end