forked from fixin.me/fixin.me
List units ordered, not using nested_set
This commit is contained in:
parent
92132768fa
commit
4e91c89153
@ -14,11 +14,14 @@ class Unit < ApplicationRecord
|
||||
acts_as_nested_set parent_column: :base_id, scope: :user, dependent: :destroy,
|
||||
order_column: :multiplier
|
||||
|
||||
scope :defaults, -> { where(user: nil) }
|
||||
|
||||
after_save if: :base do |record|
|
||||
record.move_to_ordered_child_of(record.base, :multiplier)
|
||||
end
|
||||
scope :defaults, ->{ where(user: nil) }
|
||||
scope :ordered, ->{
|
||||
parent_symbol = Arel::Nodes::NamedFunction.new(
|
||||
'COALESCE',
|
||||
[Arel::Table.new(:bases_units)[:symbol], Unit.arel_table[:symbol]]
|
||||
)
|
||||
left_outer_joins(:base).order(parent_symbol, :multiplier)
|
||||
}
|
||||
|
||||
before_destroy do
|
||||
# TODO: disallow destruction if any object depends on this unit
|
||||
|
@ -11,7 +11,7 @@ class User < ApplicationRecord
|
||||
disabled: 0, # administratively disallowed to sign in
|
||||
}, default: :active
|
||||
|
||||
has_many :units, -> { order :lft }, dependent: :destroy
|
||||
has_many :units, -> { ordered }, dependent: :destroy
|
||||
|
||||
def at_least(status)
|
||||
User.statuses[self.status] >= User.statuses[status]
|
||||
|
Loading…
x
Reference in New Issue
Block a user