【发布时间】:2018-06-30 03:43:12
【问题描述】:
查询是
Post.includes(:comments).where(:id=>post_ids).select("posts.id,posts.title, posts.description,posts.vote").group('posts.id').order("(count(distinct comments.id)) desc")
它给出了一个错误ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "comments"
【问题讨论】:
-
向我们展示您的
schema.rb文件 -
post和cmets之间有_many关系
-
我猜你的 cmets 表中缺少
post_id。 -
能把你的models定义,log中执行的sql语句和数据库表的定义放上去吗?
标签: ruby-on-rails ruby postgresql include