keruilin
keruilin

Reputation: 17552

How can I modify this SQL find-duplicate-records statement to return ActiveRecord objects?

Per my verbose question, how can I modify this SQL statement to return an array of AR objects?

"SELECT id, user_id, activity_type_id, source_id, source_type, COUNT(*) AS cnt FROM activities GROUP BY id, user_id, activity_type_id, source_id, source_type HAVING COUNT(*) > 1"

I'm using Rails 2.3.

Upvotes: 0

Views: 148

Answers (1)

Jake Dempsey
Jake Dempsey

Reputation: 6322

I saw you ask another question which looks related... are you trying to remove duplicate activities? Why not just prevent their creation in the first place with a unique index on the table and a validates uniqueness of on the activity model.

Upvotes: 1

Related Questions