diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index 32e3c87..1808672 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -47,7 +47,6 @@ class QuantitiesController < ApplicationController render_no_content(@quantity) unless @quantity.update(permitted) @ancestors = @quantity.ancestors - @quantity.depth = @ancestors.length @self_and_progenies = @quantity.with_progenies @before = @self_and_progenies.last.successive end diff --git a/app/models/quantity.rb b/app/models/quantity.rb index 3d6b52a..ffc5086 100644 --- a/app/models/quantity.rb +++ b/app/models/quantity.rb @@ -68,7 +68,7 @@ class Quantity < ApplicationRecord numbered.project( numbered[Arel.star], numbered.cast(numbered[:child_number], 'BINARY').as('path'), - ).where(root ? numbered[:id].eq(root.id) : numbered[:parent_id].eq(nil)), + ).where(numbered[root ? :id : :parent_id].eq(root)), numbered.project( numbered[Arel.star], arel_table[:path].concat(numbered[:child_number]), @@ -121,7 +121,7 @@ class Quantity < ApplicationRecord end def with_progenies - user.quantities.ordered(root: self).to_a + user.quantities.ordered(root: id).to_a end # Return: record with ID `of` with its ancestors, sorted by `depth`