ruby on rails - How to get only one db record from couple of same? -


i have records in db table can differ ids , creation/update time. how can unique records? tried way, didn't work:

msg_to_user = user.messages.new_messages.uniq 

i'll explain. user can follow post manually same post can followed user automatically. want send 1 message if post have been commented someone.

1747    test message    tamadatours 12  new 2016-01-29 06:14:04.736869  2016-01-29 06:48:55.948529  32964382 1748    test message    tamadatours 12  new 2016-01-29 06:14:04.741184  2016-01-29 06:48:55.951371  32964382 

all records in database uniq (at least because of id column, default has uniq constraint).

you want use distinct:

model.select('distinct column_name1, column_name2') 

Comments