这在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"
答案 0 :(得分:0)
只是没有联合的查询,它的工作原理! 它之前没有工作,因为它返回的结果集看起来与某些原因不同。