模型的 default_scope 中的日期条件

发布于 2024-10-09 15:38:41 字数 222 浏览 0 评论 0原文

我想确保只有具有观看日期的电影才会被带回并按该值升序排列。

我认为我非常接近以下内容:

default_scope :conditions => { :watched_date => not null },
              :order => 'watched_date ASC'

但我不知道如何为非空日期添加条件。

I want to ensure that only Movies with a watched date are brought back and ordered by that value in ascending order.

I think I'm fairly close with the following:

default_scope :conditions => { :watched_date => not null },
              :order => 'watched_date ASC'

But I don't know how to add a condition for a non-null date.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

度的依靠╰つ 2024-10-16 15:38:41

如果将条件更改为这样,它会起作用吗?:

:conditions => 'watched_date IS NOT NULL'

您可能需要包含表名称,以防它在连接中使用,如下所示:

:conditions => 'movies.watched_date IS NOT NULL'

Does it work if you change the conditions to this?:

:conditions => 'watched_date IS NOT NULL'

You might want to include the table name incase this is used in joins like so:

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