Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove items from Activerecord query resultset?

I get a resultset from a Rails find query. I want to iterate over that resultset and depending on certain criteria drop records from that resultset before passing it on for further processing. The additional criteria are external to the data held in the database and hence I can't include them in the original 'find' query.

Note I don't want to delete any records from the database just remove them from the resultset.

Please can someone give me the code to do that.

like image 776
nexar Avatar asked Sep 22 '11 12:09

nexar


1 Answers

Use reject as in

Model.find_all_by_xxx().reject { |r| r.something? } 
like image 63
Fabio Avatar answered Sep 24 '22 04:09

Fabio