1

ユーザー

  • has_many:communities
  • has_many:posts

コミュニティ

  • 所属する:user
  • has_many:posts

役職

  • 所属する:user
  • 所属する:コミュニティ

example.com/postsで投稿のすべてのレコードを表示したいのですが、ユーザーテーブルにある投稿所有者のユーザーの「last_signed_in」列で
並べ替える必要があります。

これを試しましたが、エラーが返されます未定義のメソッド `users' どうすれば解決できますか?

@orders = @community.posts.user.order("last_active_at ASC")
4

1 に答える 1

3

投稿のコレクションでユーザーオブジェクトを呼び出すことはできません。

ただし、コレクションにユーザーを含めることができます。

@community.posts.includes(:user).order("users.last_signed_in")

詳細情報: http: //guides.rubyonrails.org/active_record_querying.html#eager-loading-multiple-associations

于 2013-01-03T01:19:21.660 に答える