Auxiliary Statements doesn't work with Inheritance
Consider
# /app/models/account.rb
class Account < Account
auxiliary_statement :balance do |cte|
cte.query AccountTransaction.approved.group(:account_id)
cte.attributes col(:value).sum => :balance
cte.join_type :left
end
end
# /app/models/user.rb
class User < Account
end
The following doesn't work:
User.with(:balance).first.balance
# There's no 'balance' auxiliary statement defined
The current workaround is the following
Account.cast_records(User, filter: true).with(:balance).first.balance