present? and any? in ActiveRecord and ActiveModel

TIPS: Model.where().present? == Model.where().any? == Model.where().count > 0 Extension: Model.where().many? == Model.where().count > 1 Model.where().empty? == Model.where().count == 1 One thing different from #present? is Model.where().present? *!=* Model.present? Model.where().any? *==* Model.any? ree-1.8.7-2011.03 :029 > Benchmark.ms { PlannedRun.where("plan_id > 0").present? } => 606.235027313232 ree-1.8.7-2011.03 :030 > Benchmark.ms { PlannedRun.present? } => 0.0820159912109375 <--- Object.present? not ActiveModel#count > 0 SO My suggestion is: Using #any? at anywhere for active_record or active_model to check "any record exist?"
blog comments powered by Disqus