This commit is contained in:
cryptogopher 2025-01-16 21:37:58 +01:00
parent 2fdd770457
commit 6300273186
2 changed files with 2 additions and 3 deletions

View File

@ -47,7 +47,6 @@ class QuantitiesController < ApplicationController
render_no_content(@quantity) unless @quantity.update(permitted) render_no_content(@quantity) unless @quantity.update(permitted)
@ancestors = @quantity.ancestors @ancestors = @quantity.ancestors
@quantity.depth = @ancestors.length
@self_and_progenies = @quantity.with_progenies @self_and_progenies = @quantity.with_progenies
@before = @self_and_progenies.last.successive @before = @self_and_progenies.last.successive
end end

View File

@ -68,7 +68,7 @@ class Quantity < ApplicationRecord
numbered.project( numbered.project(
numbered[Arel.star], numbered[Arel.star],
numbered.cast(numbered[:child_number], 'BINARY').as('path'), 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.project(
numbered[Arel.star], numbered[Arel.star],
arel_table[:path].concat(numbered[:child_number]), arel_table[:path].concat(numbered[:child_number]),
@ -121,7 +121,7 @@ class Quantity < ApplicationRecord
end end
def with_progenies def with_progenies
user.quantities.ordered(root: self).to_a user.quantities.ordered(root: id).to_a
end end
# Return: record with ID `of` with its ancestors, sorted by `depth` # Return: record with ID `of` with its ancestors, sorted by `depth`