1
0

Moved Formula to separate model

This commit is contained in:
cryptogopher
2020-02-16 18:34:07 +01:00
parent aa26e66312
commit 4e537f3981
6 changed files with 73 additions and 88 deletions

View File

@@ -11,7 +11,6 @@ class CreateSchema < ActiveRecord::Migration
t.references :project
t.integer :domain
t.string :name
t.string :formula
t.string :description
# fields for awesome_nested_set
t.references :parent
@@ -20,6 +19,13 @@ class CreateSchema < ActiveRecord::Migration
t.timestamps null: false
end
create_table :formulas do |t|
t.references :quantity
t.string :code
t.boolean :zero_nil
t.timestamps null: false
end
create_table :column_views do |t|
t.references :project
t.string :name

View File

@@ -138,7 +138,7 @@ class LoadDefaults < ActiveRecord::Migration
# Calculated quantities go at the and to make sure dependencies exist
e2 = Quantity.create project: nil, domain: :diet, parent: e1, name: "Calculated",
description: "Total energy calculated from macronutrients",
formula: "4*(Proteins || 0) + 9*(Fats || 0) + 4*(Carbohydrates || 0)"
formula_attributes: {code: "4*Proteins + 9*Fats + 4*Carbohydrates", zero_nil: true}
Source.create project: nil, name: "nutrition label",
description: "nutrition facts taken from package nutrition label"