Active Stotage - has_many attached_files ,through: Parent

444 views
Skip to first unread message

Navid Farjad

unread,
Sep 5, 2019, 1:57:15 AM9/5/19
to Ruby on Rails: Talk

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

Ariel Juodziukynas

unread,
Sep 5, 2019, 9:22:30 AM9/5/19
to rubyonra...@googlegroups.com
`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.

--
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 rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5fbbb4cb-4694-497b-b9b8-b80628426065%40googlegroups.com.

Ariel Juodziukynas

unread,
Sep 5, 2019, 9:22:44 AM9/5/19
to rubyonra...@googlegroups.com

Navid Farjad

unread,
Sep 8, 2019, 7:51:16 AM9/8/19
to Ruby on Rails: Talk
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 (<ad...@onesurgery.com>) 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 rubyonra...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages