From 8ef41c9503780095e2887462cab5293fd561fe6d Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 10 Sep 2015 16:40:15 +0200 Subject: [PATCH] add helpers to transactions_query --- app/grids/transactions_query.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/grids/transactions_query.rb b/app/grids/transactions_query.rb index 36d2990..2bf0ba8 100644 --- a/app/grids/transactions_query.rb +++ b/app/grids/transactions_query.rb @@ -1,15 +1,25 @@ class TransactionsQuery + attr_reader :arel_table + def initialize user @user = user @transactions = Arel::Table.new(:transactions) @perspectived = Arel::Table.new(:perspectived_transactions) @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 def arel - Arel::SelectManager.new(ActiveRecord::Base) - .from(issued_by(User).union(:all, issued_by(Client))) - .project(Arel.star) + Arel::Nodes::TableAlias.new( + issued_by(User).union(:all, issued_by(Client)), + arel_table.name + ) end def issued_by klass