Lambda 不适用于 mongoid 的默认范围

发布于 2025-01-03 05:26:37 字数 258 浏览 1 评论 0原文

我使用以下语法创建了默认范围,但这似乎不起作用。它在加载应用程序时评估 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风和你 2025-01-10 05:26:37

编辑: 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文