FIX: actually retrieve the first 2 posts in a conversation about a flag

This commit is contained in:
Régis Hanol 2014-07-28 22:50:49 +02:00
parent f6a15893e4
commit 44ba74789b
2 changed files with 4 additions and 3 deletions

View File

@ -76,6 +76,7 @@ class Topic < ActiveRecord::Base
belongs_to :category
has_many :posts
has_many :ordered_posts, -> { order(post_number: :asc) }, class_name: "Post"
has_many :topic_allowed_users
has_many :topic_allowed_groups

View File

@ -42,7 +42,7 @@ module FlagQuery
end
post_actions = actions.order('post_actions.created_at DESC')
.includes(related_post: { topic: { posts: :user }})
.includes(related_post: { topic: { ordered_posts: :user }})
.where(post_id: post_ids)
post_actions.each do |pa|
@ -67,13 +67,13 @@ module FlagQuery
if pa.related_post && pa.related_post.topic
conversation = {}
related_topic = pa.related_post.topic
if response = related_topic.posts[0]
if response = related_topic.ordered_posts[0]
conversation[:response] = {
excerpt: excerpt(response.cooked),
user_id: response.user_id
}
user_ids << response.user_id
if reply = related_topic.posts[1]
if reply = related_topic.ordered_posts[1]
conversation[:reply] = {
excerpt: excerpt(reply.cooked),
user_id: reply.user_id