は、私は次のモデルで3.1アプリレールを持っています。
数コメント手段上:レール3.1データベースクエリ
問題は、例えばポストAは、私は、クエリは、このような何かをしたいポストB.
上の最も最近のコメントよりも新しい3件のコメントを持っている場合ということです1 =最新の10 =最も古い。
Post A
comment 1 #=>ok fetch the post
Post B
comment 2 #=>ok fetch the post
comment 3 #=>this post is fecthed go on find the next one
comment 4 #=>this post is fecthed go on find the next one
Post C
comment 5 #=>ok fetch the post
comment 6 #=>this post is fecthed go on find the next one
Post D
comment 7 #=>ok fetch the post
comment 8 #=>this post is fecthed go on find the next one
Post E
comment 9 #=>ok fetch the post
comment 10
これを行うためにエレガントなクエリを作成することはできますか?ポストテーブルのcomment_updated_atカラム:
可能な解決策は、更新することです。
FYI私はActiveRecordのを使用する:: Baseが関係の中で=>モデル化していないではありません。下記参照。 –
私はそうです!モデレータが元の投稿を編集しました。私はコードではなくテキストで書きました。コードでうまく見えるが、司会者はコードを間違っていた。今修正して申し訳ありません! –