Fix SQLite query compatibility inside WITH clause

Rename model methods to #succeeding.
This commit is contained in:
2026-10-18 02:34:57 +02:00
parent 9c51887024
commit f04c8d85be
5 changed files with 54 additions and 31 deletions
+4 -3
View File
@@ -3,6 +3,7 @@ class Unit < ApplicationRecord
belongs_to :user, optional: true
belongs_to :base, optional: true, class_name: "Unit"
# TODO: use #alias_attribute after Rails upgrade?
alias_method :parent, :base
has_many :subunits, class_name: "Unit", inverse_of: :base,
dependent: :restrict_with_error
@@ -111,13 +112,13 @@ class Unit < ApplicationRecord
.update!(base: recipient_base, **params)
end
def successive
def succeeding
units = Unit.arel_table
Unit.with(units_with_lag: user.units.left_outer_joins(:base).select(
Unit.with(lagging_units: user.units.left_outer_joins(:base).select(
units[Arel.star],
Arel::Nodes::NamedFunction.new('LAG', [units[:id]])
.over(Arel::Nodes::Window.new.order(Unit.ordered.order_values)).as('lag_id')
)).from(Arel::Table.new(:units_with_lag).as(:units))
)).from(Arel::Table.new(:lagging_units).as(:units))
.where(units[:lag_id].eq(id)).take
end
end