diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb index 88749ec..c7d4c09 100644 --- a/app/models/ingredient.rb +++ b/app/models/ingredient.rb @@ -1,7 +1,9 @@ class Ingredient < ActiveRecord::Base enum group: { other: 0, - meat: 1 + dish: 1, + recipe: 2, + meat: 3 } # Has to go before any 'dependent:' association diff --git a/app/models/measurement_routine.rb b/app/models/measurement_routine.rb index 85cf4c2..28e0c3b 100644 --- a/app/models/measurement_routine.rb +++ b/app/models/measurement_routine.rb @@ -3,9 +3,9 @@ class MeasurementRoutine < ActiveRecord::Base has_many :measurements, -> { order "taken_at DESC" }, inverse_of: :routine, foreign_key: 'routine_id', dependent: :restrict_with_error, extend: BodyTracking::ItemsWithQuantities - has_many :columns, as: :column_view, dependent: :destroy, - extend: BodyTracking::TogglableColumns - has_many :quantities, -> { order "lft" }, through: :columns + has_many :readout_columns, as: :column_view, dependent: :destroy, + class: 'QuantityColumn', extend: BodyTracking::TogglableColumns + has_many :quantities, -> { order "lft" }, through: :readout_columns validates :name, presence: true, uniqueness: {scope: :project_id} end diff --git a/app/models/column.rb b/app/models/quantity_column.rb similarity index 63% rename from app/models/column.rb rename to app/models/quantity_column.rb index 9b2736c..3d0b620 100644 --- a/app/models/column.rb +++ b/app/models/quantity_column.rb @@ -1,4 +1,4 @@ -class Column < ActiveRecord::Base +class QuantityColumn < ActiveRecord::Base belongs_to :column_view, polymorphic: true belongs_to :quantity end diff --git a/db/migrate/001_create_schema.rb b/db/migrate/001_create_schema.rb index 40175d1..c10d077 100644 --- a/db/migrate/001_create_schema.rb +++ b/db/migrate/001_create_schema.rb @@ -27,7 +27,7 @@ class CreateSchema < ActiveRecord::Migration t.timestamps null: false end - create_table :columns do |t| + create_table :quantity_columns do |t| t.references :column_view, polymorphic: true t.references :quantity end @@ -49,6 +49,7 @@ class CreateSchema < ActiveRecord::Migration t.references :source t.string :source_ident t.boolean :hidden + t.decimal :ready_amount, precision: 12, scale: 6 t.timestamps null: false end @@ -82,5 +83,21 @@ class CreateSchema < ActiveRecord::Migration t.references :unit t.timestamps null: false end + + create_table :meals do |t| + t.references :project + t.text :notes + t.timestamp :eaten_at + t.timestamps null: false + end + + create_table :compositions_ingredients do |t| + t.references :composition, polymorphic: true + t.references :ingredient + t.references :part_of + t.decimal :ready_ratio, precision: 12, scale: 6 + t.decimal :amount, precision: 12, scale: 6 + t.timestamps null: false + end end end diff --git a/lib/body_tracking/project_patch.rb b/lib/body_tracking/project_patch.rb index 1e52afe..d7eaf1c 100644 --- a/lib/body_tracking/project_patch.rb +++ b/lib/body_tracking/project_patch.rb @@ -10,8 +10,8 @@ module BodyTracking::ProjectPatch has_many :quantities, -> { order "lft" }, dependent: :destroy has_many :units, dependent: :destroy - has_many :nutrient_columns, as: :column_view, dependent: :destroy, class_name: 'Column', - extend: BodyTracking::TogglableColumns + has_many :nutrient_columns, as: :column_view, dependent: :destroy, + class_name: 'QuantityColumn', extend: BodyTracking::TogglableColumns has_many :nutrient_quantities, -> { order "lft" }, through: :nutrient_columns, source: 'quantity' end diff --git a/test/unit/column_view_test.rb b/test/unit/column_view_test.rb index 2a7e8d3..55e7352 100644 --- a/test/unit/column_view_test.rb +++ b/test/unit/column_view_test.rb @@ -1,6 +1,6 @@ require File.expand_path('../../test_helper', __FILE__) -class ColumnViewTest < ActiveSupport::TestCase +class QuantityColumnTest < ActiveSupport::TestCase # Replace this with your real tests. def test_truth