Fixed Quantity defaults import after removing :name uniqueness
Added awesome_nested_set #each_with_path
This commit is contained in:
25
lib/body_tracking/awesome_nested_set_patch.rb
Normal file
25
lib/body_tracking/awesome_nested_set_patch.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module BodyTracking::AwesomeNestedSetPatch
|
||||
CollectiveIdea::Acts::NestedSet.class_eval do
|
||||
module CollectiveIdea::Acts::NestedSet
|
||||
class Iterator
|
||||
def each_with_path
|
||||
return to_enum(__method__) { objects.length } unless block_given?
|
||||
|
||||
path = [nil]
|
||||
objects.each do |o|
|
||||
path[path.rindex(o.parent)+1..-1] = o
|
||||
yield [o, path.map { |q| q.try(:name) }.join('::')]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Model
|
||||
module ClassMethods
|
||||
def each_with_path(objects, &block)
|
||||
Iterator.new(objects).each_with_path(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
module BodyTracking::ProjectPatch
|
||||
Project.class_eval do
|
||||
has_many :sources, dependent: :destroy
|
||||
# TODO: includes(:parent) ?
|
||||
has_many :quantities, -> { order "lft" }, inverse_of: :project, dependent: :destroy
|
||||
has_many :formulas, through: :quantities
|
||||
has_many :units, dependent: :destroy
|
||||
|
||||
Reference in New Issue
Block a user