Martin
Martin

Reputation: 11336

Retrieve all objects with errors from model on ActiveRecord

There's an easy why that I don't remember to retrieve all invalid objects saved in the database from rails console.

Any idea how?

Upvotes: 4

Views: 2262

Answers (1)

Patrick Klingemann
Patrick Klingemann

Reputation: 9014

say your model is called Widget, then:

Widget.all.select(&:invalid?)

That's likely to be very slow if you have a lot of data, but you have to retrieve the records from the database if you want to check their validity.

Upvotes: 12

Related Questions