Skip to content

Commit

Permalink
add issuer name to transactions query
Browse files Browse the repository at this point in the history
  • Loading branch information
iasoon committed Sep 10, 2015
1 parent 7e251e1 commit 7fe2849
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/grids/transactions_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,32 @@ def initialize user
end

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)
.from(transactions)
.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(
@perspectived[:amount],
@perspectived[:date],
@perspectived[:message],
@peers[:name].as('peer'),
@perspectived[:issuer_id],
@perspectived[:message]
issuers[:name].as('issuer')
)
end

def transactions
Arel::Nodes::TableAlias.new(incoming.union(outgoing), @perspectived.name)
Arel::Nodes::TableAlias.new(
incoming.union(outgoing),
@perspectived.name
)
end

def outgoing
Expand Down

0 comments on commit 7fe2849

Please sign in to comment.