Default Units index

This commit is contained in:
2024-11-10 21:30:19 +01:00
parent aebbe11bef
commit 51011951f9
5 changed files with 35 additions and 3 deletions

View File

@@ -15,10 +15,11 @@ class Unit < ApplicationRecord
scope :defaults, ->{ where(user: nil) }
scope :with_defaults, ->{ self.or(Unit.where(user: nil)) }
scope :default_diff, ->{
scope :defaults_diff, ->{
other_units = Unit.arel_table.alias('other_units')
other_bases_units = Unit.arel_table.alias('other_bases_units')
constraints = other_bases_units[:id].eq(other_units[:base_id])
.and(other_bases_units[:symbol].eq(Arel::Table.new(:bases_units)[:symbol]))
.and(other_units[:symbol].eq(arel_table[:symbol]))
.and(other_units[:user_id].not_eq(arel_table[:user_id]))
@@ -46,4 +47,8 @@ class Unit < ApplicationRecord
def movable?
subunits.empty?
end
def default?
user.nil?
end
end