1
0

Added Targets table

Fixed Quantity#after_save for default quantities
This commit is contained in:
cryptogopher 2020-06-18 01:53:09 +02:00
parent 1a807d24d7
commit 61498018e7
2 changed files with 11 additions and 1 deletions

View File

@ -26,7 +26,8 @@ class Quantity < ActiveRecord::Base
# be no other way to validate against newly changed :name
after_save do
next unless name_changed? || changes.empty?
formulas = project.formulas.where('formulas.code LIKE ?', "%#{name}%").includes(:quantity)
formulas = Formula.joins(:quantity).where(quantities: {project_id: project})
.where('formulas.code LIKE ?', "%#{name}%").includes(:quantity)
next unless formulas.exists?
quantity_names = formulas.reject(&:valid?)

View File

@ -92,5 +92,14 @@ class CreateSchema < ActiveRecord::Migration
t.timestamp :taken_at
t.timestamps null: false
end
create_table :targets do |t|
t.references :goal
t.references :threshold
t.string :condition
t.string :scope
t.date :effective_from
t.timestamps null: false
end
end
end