List all uploads of a Post/Topic


(Leo) #1

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?


(Jeff Atwood) #2

@tgxworld might know.


(Alan Tan) #3

@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?


(Leo) #4

@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


(Alan Tan) #5

Is Sidekiq running? The relationship is only created in


(Leo) #6

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: