如何干燥 Mongoid 模型的共享范围?
我有一些 Mongoid 模型类,它们都有一个 :datetime 字段。我想查询这些模型以找出属于今天日期的记录。查询如下所示:
scope today, where(:datetime.gt => DateTime.now.beginning_of_day, :datetime.lt => DateTime.now.end_of_day)
目前,上述范围代码在所有模型类中重复。我怎样才能把它弄干呢?
I have a few Mongoid model classes that all have a :datetime field. I would like to query these models to find out records that fall under today's date. The query would look like this:
scope today, where(:datetime.gt => DateTime.now.beginning_of_day, :datetime.lt => DateTime.now.end_of_day)
Currently, the above scope code are duplicated within all the model classes. How do I dry this up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的事情是:
The simples thing is: