From 61498018e7e938bd576a2fd410d5815d357c507b Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Thu, 18 Jun 2020 01:53:09 +0200 Subject: [PATCH] Added Targets table Fixed Quantity#after_save for default quantities --- app/models/quantity.rb | 3 ++- db/migrate/001_create_schema.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/quantity.rb b/app/models/quantity.rb index e6222d4..07e7fe1 100644 --- a/app/models/quantity.rb +++ b/app/models/quantity.rb @@ -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?) diff --git a/db/migrate/001_create_schema.rb b/db/migrate/001_create_schema.rb index 39e4570..19c6a2b 100644 --- a/db/migrate/001_create_schema.rb +++ b/db/migrate/001_create_schema.rb @@ -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