There's a lot of similiar questions like this, but couldn't find good answer for me.
I have EntryVote
model with fields user_id
, entry_id
and some others.
I want to create simple rake task to remove duplicates for user_id
, entry_id
groups (doesn't matter whic record left from the group).
What's the best way of doing it?
For example:
id, user_id, entry_id
1,1,1
2,1,1
3,1,1
4,5,6
5,5,6
6,7,7
I get:
1,1,1
4,5,6
6,7,7
I know how to select user_id, entry_id for deduplication, but not sure how to work with it afterward:
EntryVote.select('user_id, entry_id').group('user_id,entry_id').having('count() > 1')