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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -