Added :meals and :compositions_ingredients tables
Changed Column -> QuantityColumn Updated :ingredients table to handle recipes
This commit is contained in:
parent
dbb8bdc62e
commit
ced06a25bc
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
class Column < ActiveRecord::Base
|
||||
class QuantityColumn < ActiveRecord::Base
|
||||
belongs_to :column_view, polymorphic: true
|
||||
belongs_to :quantity
|
||||
end
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user