From 7e251e19cb8b22d1340bb543ae327dbc93bfec90 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 10 Sep 2015 15:05:46 +0200 Subject: [PATCH] update transactions query to include peer --- app/grids/transactions_query.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/grids/transactions_query.rb b/app/grids/transactions_query.rb index e7f0ed5..032ab97 100644 --- a/app/grids/transactions_query.rb +++ b/app/grids/transactions_query.rb @@ -2,22 +2,25 @@ class TransactionsQuery def initialize user @user = user @transactions = Arel::Table.new(:transactions) + @perspectived = Arel::Table.new(:perspectived_transactions) + @peers = Arel::Table.new(:users).alias('peers') end def arel Arel::SelectManager.new(ActiveRecord::Base) .from(transactions) + .join(@peers).on(@peers[:id].eq(@perspectived[:peer_id])) .project( - @transactions[:amount], - @transactions[:date], - @transactions[:peer_id], - @transactions[:issuer_id], - @transactions[:message] + @perspectived[:amount], + @perspectived[:date], + @peers[:name].as('peer'), + @perspectived[:issuer_id], + @perspectived[:message] ) end def transactions - Arel::Nodes::UnionAll.new(outgoing, incoming) + Arel::Nodes::TableAlias.new(incoming.union(outgoing), @perspectived.name) end def outgoing @@ -28,7 +31,8 @@ class TransactionsQuery @transactions[:creditor_id].as('peer_id'), @transactions[:created_at].as('date'), @transactions[:issuer_id], - @transactions[:issuer_type] + @transactions[:issuer_type], + @transactions[:message] ) end @@ -41,7 +45,8 @@ class TransactionsQuery @transactions[:debtor_id].as('peer_id'), @transactions[:created_at].as('date'), @transactions[:issuer_id], - @transactions[:issuer_type] + @transactions[:issuer_type], + @transactions[:message] ) end end