【发布时间】:2011-07-12 09:11:53
【问题描述】:
我正在为这个使用 Mongoid 的项目构建一个 REST api。
我已设置以下内容来捕获Mongoid::Errors::DocumentNotFound 异常:
rescue_from Mongoid::Errors::DocumentNotFound in my base controller
在我的控制器中,我有这个查询代码:
@current_account.users.find(:first, :conditions => {:name => "some_name"})
上面的查询只返回nil。它不会引发异常。
也尝试了另一种语法:
User.find(:conditions => {:name => "same"}).first
所有这些方法都只是在内部运行 where 而 afaik where 不会引发异常,它只是返回 []
那么有什么办法可以解决这个问题呢?我想要部分动态查找器,但也应该引发异常?
【问题讨论】: