Lambda 不适用于 mongoid 的默认范围
我使用以下语法创建了默认范围,但这似乎不起作用。它在加载应用程序时评估 5.mines.ago,然后使用相同的评估时间来查询数据。
default_scope -> { where(:created_at.gt => 5.minutes.ago) }
我正在使用 mongoid 2.4.3、rails 3.1.3 和 ruby 1.9.3-p0。
任何建议都会对我有很大帮助。
谢谢
I created default scope using the following syntax but this doesn't seem to work. It evaluates 5.minutes.ago while loading the app and then uses same evaluated time to query data.
default_scope -> { where(:created_at.gt => 5.minutes.ago) }
I'm using mongoid 2.4.3, rails 3.1.3 and ruby 1.9.3-p0.
Any suggestion would be great help to me.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑: Mongoid 3.0.0 引入了对带有 lambda 的默认作用域的支持。
Mongoid 尚不支持 lambda 的默认作用域(请参阅 GitHub 上的问题)。
Edit: Mongoid 3.0.0 introduced support for default scopes with lambdas.
Mongoid does not yet support default scopes with lambdas (see the issue on GitHub).