PG :: UndefinedTable:错误:缺少FROM子句 - 使用"包含"Rails排序关联记录

Not*_*ere 5 join ruby-on-rails include

我有一个应用程序,我在当前用户显示帖子(posts.current_user).我想通过comment.date排序来显示最近评论过的帖子.它似乎不想这样做...我一直在:

PG :: UndefinedTable:错误:缺少表"注释"的FROM子句条目

我的控制器

 def_index
 @posts = current_user.posts.includes(:comment).order("comment.date ASC").includes(:image)
 end
Run Code Online (Sandbox Code Playgroud)

我试过加入并包括一个我似乎无法解决这个问题.谢谢.

apn*_*ing 16

尝试:

 @posts = current_user.posts.joins(:comment).order("comments.date ASC").includes(:image)
Run Code Online (Sandbox Code Playgroud)

说明:

  • 你需要加入
  • 按顺序,您必须引用表的名称,而不是关联的名称

  • 啊......等等......我在评论中错过了's'!就是这样.谢谢! (3认同)