Updated comments, added before_destroy where applicable
This commit is contained in:
parent
8d368d6aa5
commit
f769fff930
@ -43,7 +43,6 @@ class IngredientsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
# FIXME: don't destroy if any meal depend on ingredient
|
||||
if @ingredient.destroy
|
||||
flash[:notice] = 'Deleted ingredient'
|
||||
end
|
||||
|
@ -39,7 +39,6 @@ class MeasurementsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
# FIXME: don't destroy if there are any readout values
|
||||
if @measurement.destroy
|
||||
flash[:notice] = 'Deleted measurement'
|
||||
end
|
||||
|
@ -22,7 +22,6 @@ class SourcesController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
# FIXME: do not destroy if anything depends on it
|
||||
if @source.destroy
|
||||
flash[:notice] = 'Deleted source'
|
||||
end
|
||||
|
@ -22,7 +22,6 @@ class UnitsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
# FIXME: do not destroy if anything depends on it
|
||||
if @unit.destroy
|
||||
flash[:notice] = 'Deleted unit'
|
||||
end
|
||||
|
@ -6,6 +6,12 @@ class Ingredient < ActiveRecord::Base
|
||||
meat: 1
|
||||
}
|
||||
|
||||
# Has to go before any 'dependent:' association
|
||||
before_destroy do
|
||||
# FIXME: disallow destruction if any object depends on this quantity
|
||||
nil
|
||||
end
|
||||
|
||||
belongs_to :project, required: true
|
||||
belongs_to :ref_unit, class_name: 'Unit', required: true
|
||||
belongs_to :source, required: false
|
||||
|
@ -7,7 +7,8 @@ class Measurement < ActiveRecord::Base
|
||||
accepts_nested_attributes_for :readouts, allow_destroy: true, reject_if: proc { |attrs|
|
||||
attrs['quantity_id'].blank? && attrs['value'].blank?
|
||||
}
|
||||
# Readout (quantity_id, unit_id) pair uniqueness check for nested attributes
|
||||
# Readout quantity_id + unit_id uniqueness validation. Cannot be effectively
|
||||
# checked on Readout model level.
|
||||
validate do
|
||||
quantities = self.readouts.map { |r| [r.quantity_id, r.unit_id] }
|
||||
if quantities.length != quantities.uniq.length
|
||||
|
@ -7,6 +7,12 @@ class Quantity < ActiveRecord::Base
|
||||
exercise: 2
|
||||
}
|
||||
|
||||
# Has to go before any 'dependent:' association
|
||||
before_destroy do
|
||||
# FIXME: disallow destruction if any object depends on this quantity
|
||||
nil
|
||||
end
|
||||
|
||||
acts_as_nested_set dependent: :destroy, scope: :project
|
||||
belongs_to :project, required: false
|
||||
|
||||
|
@ -2,4 +2,10 @@ class Source < ActiveRecord::Base
|
||||
belongs_to :project, required: false
|
||||
|
||||
validates :name, presence: true, uniqueness: {scope: :project_id}
|
||||
|
||||
# Has to go before any 'dependent:' association
|
||||
before_destroy do
|
||||
# FIXME: disallow destruction if any object depends on this quantity
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
@ -2,4 +2,10 @@ class Unit < ActiveRecord::Base
|
||||
belongs_to :project, required: false
|
||||
|
||||
validates :shortname, presence: true, uniqueness: {scope: :project_id}
|
||||
|
||||
# Has to go before any 'dependent:' association
|
||||
before_destroy do
|
||||
# FIXME: disallow destruction if any object depends on this quantity
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user