不明确的表引用 [英] Ambiguous table reference
问题描述
这个问题似乎很简单,但我从来没有遇到过一个像这样。
This problem seems fairly simple, but I've never encountered one like this.
下面是设置:
Post has_many :reader_links
Post has_many :readers, :through => :reader_links
我需要找出是否有读者阅读文章。
I need to find out if there are readers reading a post.
@ post.reader_links.where('created_at> =',45.minutes.ago)?.ANY
的伟大工程。
@ post.readers.where('created_at> =',45.minutes.ago)?,任何
引发的暧昧表列的错误,因为它混淆是否 created_at
列意味着读者对象或< STRONG> reader_link 对象。这是因为类读者实际上是用户。如何查询读者谁被reader_links在38分钟以前?
throws an ambiguous table column error because it's confused whether the created_at
column means that of reader object or reader_link object. This happens because the class of a reader is actually User. How do I query readers who were created by reader_links 45 minutes ago?
我正在寻找像..
@ post.readers.where('reader_link.created_at&GT; =',45.minutes.ago)
推荐答案
如果我得到它的权利,你只需要指定 created_at
列你在谈论:
If I get it right, you just need to specify which created_at
column you're talking about:
@post.readers.where('reader_links.created_at >= ?', 45.minutes.ago).any?
这篇关于不明确的表引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!