# List all uploads of a Post/Topic

**URL:** https://meta.discourse.org/t/list-all-uploads-of-a-post-topic/53507
**Category:** Development
**Created:** [11월 29, 2016, 1:35오전 UTC](https://meta.discourse.org/t/list-all-uploads-of-a-post-topic/53507 "2016-11-29T01:35:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![leo.proctor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leo.proctor/32/216158_2.png) [@leo.proctor](https://meta.discourse.org/u/leo.proctor)
#### Post date: [11월 29, 2016, 1:35오전 UTC](https://meta.discourse.org/t/list-all-uploads-of-a-post-topic/53507/1 "2016-11-29T01:35:03Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [11월 29, 2016, 1:49오전 UTC](https://meta.discourse.org/t/list-all-uploads-of-a-post-topic/53507/2 "2016-11-29T01:49:25Z")

</div>

@tgxworld might know.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [11월 29, 2016, 1:58오전 UTC](https://meta.discourse.org/t/list-all-uploads-of-a-post-topic/53507/3 "2016-11-29T01:58:38Z")

</div>

@leo.proctor

> [@leo.proctor](#):
>
> Is there any method defined that lists all the uploads of a post or tell us which post upload belongs to?

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

> [@leo.proctor](#):
>
> Why PostUpload is not used?

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

---

<div class="post-metadata">

### Author: ![leo.proctor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leo.proctor/32/216158_2.png) [@leo.proctor](https://meta.discourse.org/u/leo.proctor)
#### Post date: [11월 29, 2016, 2:12오전 UTC](https://meta.discourse.org/t/list-all-uploads-of-a-post-topic/53507/4 "2016-11-29T02:12:59Z")

</div>

@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

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [11월 29, 2016, 2:24오전 UTC](https://meta.discourse.org/t/list-all-uploads-of-a-post-topic/53507/5 "2016-11-29T02:24:21Z")

</div>

Is Sidekiq running? The relationship is only created in

> <https://github.com/discourse/discourse/blob/main/lib/cooked_post_processor.rb#L60-L76>

---

<div class="post-metadata">

### Author: ![leo.proctor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leo.proctor/32/216158_2.png) [@leo.proctor](https://meta.discourse.org/u/leo.proctor)
#### Post date: [11월 29, 2016, 3:14오전 UTC](https://meta.discourse.org/t/list-all-uploads-of-a-post-topic/53507/6 "2016-11-29T03:14:54Z")

</div>

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 🙂
