List all uploads of a Post/Topic

Is there any method defined that lists all the uploads of a post or tell us which post upload belongs to? I see there are relations defined in Post model

has_many :post_uploads
has_many :uploads, through: :post_uploads

But it is hardly used. If I upload an image to a post, it updates the “raw” field in Post to determine the uploads. There is no direct relationship. Why PostUpload is not used?

2 Likes

@tgxworld might know.

@leo.proctor

With any instance of Post, you can do post.uploads to fetch all the Uploads that belong to a post.

PostUpload is being used in through: :post_uploads. I think there might be some confusion here. Perhaps you can provide me with more context?

2 Likes

@tgxworld

I pulled the latest code from master, created a new topic and uploaded an image. Now in rails console

Post.last.uploads # =>
PostUpload.count # => 0
Upload.last #=> contains the uploaded image
Post.last.raw #=> contains a link to uploaded image

Is Sidekiq running? The relationship is only created in

https://github.com/discourse/discourse/blob/master/lib/cooked_post_processor.rb#L60-L76

4 Likes

Ah thanks, I think I found the problem. keep_reverse_index_up_to_date uses a/@href value to determine upload. I’m currently using a plugin for private attachments, that doesn’t store absolute url of attachments in a/@href. I may need to overwrite keep_reverse_index_up_to_date. Thanks anyways :slight_smile:

3 Likes