Active Stotage - has_many attached_files ,through: Parent

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Active Stotage - has_many attached_files ,through: Parent

Navid Farjad

let's say there are 2 models.

user model:

has_many :posts

post model:

belongs_to :user

has_many_attached :files, dependent: :destroy

what I want is simply all files of the user. something like:

has _may :post_files , through: posts, class_name: "XXX"

or any other way which can give me all the files of the user.

so I want all files of all posts which belong to the user. like user.post_files

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5fbbb4cb-4694-497b-b9b8-b80628426065%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Active Stotage - has_many attached_files ,through: Parent

Ariel Juodziukynas
`has_many_attached :files` actually sets to has_many relationships: `has_many :files_attachments` and `has_many :files_blobs`, you could use those has_many relationships to use on your user's has_many :through relationship.

El jue., 5 sept. 2019 a las 2:57, Navid Farjad (<[hidden email]>) escribió:

let's say there are 2 models.

user model:

has_many :posts

post model:

belongs_to :user

has_many_attached :files, dependent: :destroy

what I want is simply all files of the user. something like:

has _may :post_files , through: posts, class_name: "XXX"

or any other way which can give me all the files of the user.

so I want all files of all posts which belong to the user. like user.post_files

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5fbbb4cb-4694-497b-b9b8-b80628426065%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcCLj67VZAEcfVZ7Kd0yuT-kRwJBGW3nsp769Wftr68J1A%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Active Stotage - has_many attached_files ,through: Parent

Ariel Juodziukynas

El jue., 5 sept. 2019 a las 10:21, Ariel Juodziukynas (<[hidden email]>) escribió:
`has_many_attached :files` actually sets to has_many relationships: `has_many :files_attachments` and `has_many :files_blobs`, you could use those has_many relationships to use on your user's has_many :through relationship.

El jue., 5 sept. 2019 a las 2:57, Navid Farjad (<[hidden email]>) escribió:

let's say there are 2 models.

user model:

has_many :posts

post model:

belongs_to :user

has_many_attached :files, dependent: :destroy

what I want is simply all files of the user. something like:

has _may :post_files , through: posts, class_name: "XXX"

or any other way which can give me all the files of the user.

so I want all files of all posts which belong to the user. like user.post_files

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5fbbb4cb-4694-497b-b9b8-b80628426065%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcDrJvfwOm5brmrvAE%2BuHN2iXWRs1-fs2X%2BmnFzU-8J%2BuA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Active Stotage - has_many attached_files ,through: Parent

Navid Farjad
In reply to this post by Ariel Juodziukynas
Thank you so much for your help. it works now!

On Thursday, September 5, 2019 at 4:22:30 PM UTC+3, Ariel Juodziukynas wrote:
`has_many_attached :files` actually sets to has_many relationships: `has_many :files_attachments` and `has_many :files_blobs`, you could use those has_many relationships to use on your user's has_many :through relationship.

El jue., 5 sept. 2019 a las 2:57, Navid Farjad (<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="sIElGVihAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ad...@...>) escribió:

let's say there are 2 models.

user model:

has_many :posts

post model:

belongs_to :user

has_many_attached :files, dependent: :destroy

what I want is simply all files of the user. something like:

has _may :post_files , through: posts, class_name: "XXX"

or any other way which can give me all the files of the user.

so I want all files of all posts which belong to the user. like user.post_files

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="sIElGVihAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/5fbbb4cb-4694-497b-b9b8-b80628426065%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/5fbbb4cb-4694-497b-b9b8-b80628426065%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/5fbbb4cb-4694-497b-b9b8-b80628426065%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/5fbbb4cb-4694-497b-b9b8-b80628426065%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/709c4ffd-12d8-417a-9774-881af3bee231%40googlegroups.com.