add issuer name to transactions query
This commit is contained in:
parent
2d753146f0
commit
81b30902f7
1 changed files with 15 additions and 3 deletions
|
@ -7,20 +7,32 @@ class TransactionsQuery
|
||||||
end
|
end
|
||||||
|
|
||||||
def arel
|
def arel
|
||||||
|
Arel::SelectManager.new(ActiveRecord::Base)
|
||||||
|
.from(issued_by(User).union(issued_by(Client)))
|
||||||
|
.project(Arel.star)
|
||||||
|
end
|
||||||
|
|
||||||
|
def issued_by klass
|
||||||
|
issuers = klass.arel_table.alias('issuer')
|
||||||
Arel::SelectManager.new(ActiveRecord::Base)
|
Arel::SelectManager.new(ActiveRecord::Base)
|
||||||
.from(transactions)
|
.from(transactions)
|
||||||
.join(@peers).on(@peers[:id].eq(@perspectived[:peer_id]))
|
.join(@peers).on(@peers[:id].eq(@perspectived[:peer_id]))
|
||||||
|
.join(issuers).on(issuers[:id].eq(@perspectived[:issuer_id]))
|
||||||
|
.where(@perspectived[:issuer_type].eq(klass.name))
|
||||||
.project(
|
.project(
|
||||||
@perspectived[:amount],
|
@perspectived[:amount],
|
||||||
@perspectived[:date],
|
@perspectived[:date],
|
||||||
|
@perspectived[:message],
|
||||||
@peers[:name].as('peer'),
|
@peers[:name].as('peer'),
|
||||||
@perspectived[:issuer_id],
|
issuers[:name].as('issuer')
|
||||||
@perspectived[:message]
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def transactions
|
def transactions
|
||||||
Arel::Nodes::TableAlias.new(incoming.union(outgoing), @perspectived.name)
|
Arel::Nodes::TableAlias.new(
|
||||||
|
incoming.union(outgoing),
|
||||||
|
@perspectived.name
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def outgoing
|
def outgoing
|
||||||
|
|
Loading…
Reference in a new issue