如何获取主题中第一帖回复的ID?

您好!
我遇到了一个问题,不确定是不是个问题。每当 user1 创建一个新主题,user2 回复该主题的第一个帖子时,它会显示“reply_to_post_number = nil”和“reply_to_user_id = nil”。即使其他用户回复该主题的帖子,它仍然显示“reply_to_post_number = nil”和“reply_to_user_id = nil”。这是为什么?有没有办法检索“reply_to_post_number”和“reply_to_user_id”?任何帮助都将不胜感激。

回复 OP(使用以下任一按钮)

是主题回复,不会获取这些值;如果它们为 nil,您可以通过 Topic#first_post 访问 OP

例如:

Post.find(1507683) # 此帖子
Post.find(1507683).topic # 此主题 => id=306187
Post.find(1507683).topic.first_post # 此主题的 OP => id=1507671
Post.find(1507683).topic.first_post.user # 此主题的创建者 => id=139851
1 个赞

感谢您的回复。我已成功获取该主题的第一个帖子。实际上,我想要的是回复该主题第一个帖子的ID。

我认为那是

Post.where(topic_id: 306187, reply_to_post_number: nil).where("post_number>1")
2 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.