ruby-on-rails - Missing from-clause entry for table/undefined table 错误

标签 ruby-on-rails postgresql heroku pg

这在 SQLite 中本地有效,但是当我推送到 heroku 时,我遇到了这个问题。

只有当我在 ORDER BY 中结束语句时才会出现此问题,否则不会给我带来问题。这就像它把对话分成两个对话,然后混淆了两个,我不记得这个错误发生在更早的时候——我可以发誓它是有效的。

抱歉,这太复杂了......

SELECT distinct conversations.*, receipts.is_read, profiles.nickname 
FROM conversations INNER JOIN notifications 
ON notifications.conversation_id = conversations.id 
INNER JOIN receipts ON receipts.notification_id = notifications.id 
INNER JOIN profiles ON profiles.id = notifications.sender_id 
WHERE (receipts.mailbox_type = 'inbox' AND ((receipts.receiver_id = #{self.id})))
  UNION
SELECT distinct conversations.*, receipts.is_read, profiles.nickname 
FROM conversations INNER JOIN notifications 
ON notifications.conversation_id = conversations.id 
INNER JOIN receipts ON receipts.notification_id = notifications.id 
INNER JOIN profiles on profiles.id = notifications.sender_id 
WHERE (receipts.mailbox_type = 'sentbox' AND ((receipts.receiver_id = #{self.id}))) 
ORDER BY conversations.updated_at desc

但是 Heroku 日志显示此错误。

2014-07-03T09:59:12.485350+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "conversations"
2014-07-03T09:59:12.761705+00:00 app[web.1]: PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "conversations"

http://pastebin.com/eNkBdkYR

最佳答案

只是在没有联合的情况下进行了查询,并且有效! 它之前没有工作,因为它返回的结果集因某些原因看起来不同。

关于ruby-on-rails - Missing from-clause entry for table/undefined table 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24550693/

相关文章:

javascript - Rails 删除链接有点太多了,为什么?

javascript - 通过 axios.post() 与数据库 react 按钮连接

ruby-on-rails - Proc在不同范围内表现不同

ruby-on-rails - mongodb 中的高效下采样

python - 有没有一种方法可以使用 pip 安装 psycopg2 而无需在主机系统上安装 postgres

windows - 用户 "user"的 PostgreSQL 密码验证失败

linux - 获取 Heroku dynos 的 IP

ruby-on-rails - 如何在 Heroku 上分析不一致的 H12 超时

python - celery + Django 错误 : TypeError: 'Settings' object is not subscriptable

ruby-on-rails - Netbeans 出现问题 : Rails erb/rhtml intellisense?