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
Post a Comment