How to obtain the ID of the reply to the first post in a topic?

Hi!
I’ve encountered an issue, and I’m unsure whether it’s a problem or not. Whenever user1 creates a new topic, and user2 replies to the first post in that topic, it shows ‘reply_to_post_number = nil’ and ‘reply_to_user_id = nil’. Even when other users reply to that topic’s post, it still shows ‘reply_to_post_number = nil’ and ‘reply_to_user_id = nil’. Why is this happening? Is there any way to retrieve the ‘reply_to_post_number’ and ‘reply_to_user_id’? Any help would be appreciated.

Replies to the OP (using either of these buttons)

are topic replies and don’t get these values; if they’re nil you can access the OP via Topic#first_post

e.g.:

Post.find(1507683) # this post
Post.find(1507683).topic # this topic => id=306187
Post.find(1507683).topic.first_post # this topic's OP => id=1507671
Post.find(1507683).topic.first_post.user # the topic creator => id=139851
1 Like

Thank you for your response. I was able to obtain the topic’s first post. Actually, I want the ID of the reply given to that topic’s first post.

I think that’s

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

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