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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -