B
B
Bogdan2017-10-27 15:32:00
Ruby on Rails
Bogdan, 2017-10-27 15:32:00

Getting result in Activerecord?

Hello. There is such a command in Activerecord, how can I get the result of the last SELECT

sql = <<-SQL.squish
  BEGIN;
  CREATE TEMP TABLE timesheets_get ( child_code )
    ON COMMIT DROP
    AS ( VALUES
      ( '6061788 '::VARCHAR(9) )
    );

  CREATE INDEX ON timesheets_get( child_code );

  SELECT bb.id, aa.*
    FROM timesheets_get aa
    LEFT JOIN children bb ON aa.child_code = bb.code;

  COMMIT;
SQL

result = ActiveRecord::Base.connection.execute( sql )

puts result

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Ponomarev, 2017-10-28
@ilyario

Try this.

ActiveRecord::Base.connection.execute( sql ).each |row|
  p row
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question