ruby on rails - Matching Records at database level -


i'm using ruby on rails 5 , have table called transaction(reference,id). table has nth transactions @ each point, @ 2 transactions have same reference number different ids. how match or reconcile 2 transactions matching reference or pair them in 1 select row @ database level?(tried using loops, slow large transactions). using postgresql

use group by

transaction.group_by(&:reference).each |reference, transaction|   p "#{reference} -> #{transaction.map(&:class).join(', ')}" end  output  "#reference number -> transaction" "#reference number -> transaction" "#reference number -> transaction, transaction" 

try this


Comments

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -