【发布时间】:2017-07-20 04:47:01
【问题描述】:
我正在尝试将 joins 与 where 子句组合,但 where 子句不是测试相等,而是测试大于或等于。
我知道在标准的 where 子句中,我可以这样做:
Group.where("vote_deadline_at <= ?", Time.now)
查找投票截止日期在未来的所有组。
但是,如果这是在 joins 之后出现的,像这样:
User.likes.where(liked_type: "Post").joins("INNER JOIN posts ON posts.id = liked_id").where(posts: {context_type:"Group"}).joins("INNER JOIN groups ON groups.id = posts.context_id").where(groups: {"vote_deadline_at <= ?",Time.now})
直到最后的where(groups: {"vote_deadline_at <= ?",Time.now}) 子句一切正常。它返回一个 186 行的 ActiveRecord 集合。但是,当我添加最后的 where 子句时,我得到了错误:
SyntaxError: unexpected '}', expecting end-of-input
...ote_deadline_at <= ?",Time.now})
有没有什么方法可以使用 where 子句进一步过滤我的结果,该子句仅选择 groups.vote_deadline_at 在未来(即小于或等于 Time.now)的行?
【问题讨论】:
标签: ruby-on-rails ruby join activerecord where-clause