add helpers to transactions_query
This commit is contained in:
parent
bd99e150a4
commit
8ef41c9503
1 changed files with 13 additions and 3 deletions
|
@ -1,15 +1,25 @@
|
||||||
class TransactionsQuery
|
class TransactionsQuery
|
||||||
|
attr_reader :arel_table
|
||||||
|
|
||||||
def initialize user
|
def initialize user
|
||||||
@user = user
|
@user = user
|
||||||
@transactions = Arel::Table.new(:transactions)
|
@transactions = Arel::Table.new(:transactions)
|
||||||
@perspectived = Arel::Table.new(:perspectived_transactions)
|
@perspectived = Arel::Table.new(:perspectived_transactions)
|
||||||
@peers = Arel::Table.new(:users).alias('peers')
|
@peers = Arel::Table.new(:users).alias('peers')
|
||||||
|
@arel_table = Arel::Table.new(@user.name.concat('_transactions'))
|
||||||
|
end
|
||||||
|
|
||||||
|
def query
|
||||||
|
Arel::SelectManager.new(ActiveRecord::Base)
|
||||||
|
.from(arel)
|
||||||
|
.project(Arel.star)
|
||||||
end
|
end
|
||||||
|
|
||||||
def arel
|
def arel
|
||||||
Arel::SelectManager.new(ActiveRecord::Base)
|
Arel::Nodes::TableAlias.new(
|
||||||
.from(issued_by(User).union(:all, issued_by(Client)))
|
issued_by(User).union(:all, issued_by(Client)),
|
||||||
.project(Arel.star)
|
arel_table.name
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def issued_by klass
|
def issued_by klass
|
||||||
|
|
Loading…
Reference in a new issue