Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 343
Martin Avatar asked Dec 15 '22 23:12

Martin


1 Answers

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.

like image 116
Patrick Klingemann Avatar answered Jan 14 '23 06:01

Patrick Klingemann