lundi 18 mai 2015

How do I check the database if it has exactly one record?

How do I check if there is exactly one record in active-record? I can do

@items.count == 1

but lately I notice it takes 90ms while other queries take 20ms. Sometimes the count method for some things take a long time. So is there a method that just checks for 1?

@items.only_one_exist?

Aucun commentaire:

Enregistrer un commentaire