ruby on rails - How can I delete duplicates based on two attributes? -


my model simple:

create_table "stack_items", force: true |t|   t.integer  "stack_id"   t.integer  "service_id"   t.text     "description" end 

i need remove duplicate stackitem records have same stack_id , service_id. if 1 of dupes has in description field, have keep one, , delete other duplicate.

 stackitem.group(:stack_id, :service_id).order("count_id desc").where("count(*) > 1") 

so far i've tried grab duplicates it's saying cannot count within statement.

activerecord::statementinvalid: pg::groupingerror: error: aggregate functions not allowed in where

how can achieve using rails 4 , activerecord? database postgresql.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -