I've spent the night deep diving into join tables of ActiveRecord and I've come out with a better understanding, but still not quite sure how to do what I want to do.
I have an Album model that is connected to Categories through a Album_Categories Table.
I also have a Gallery Table.
I want to create a way for Gallery to be aware of a category that is created when an Album is created, when a Gallery creates a category, and also when a category is created indpendent of either a Gallery or Album. If I disassociate either a Category from either an Album or a Gallery it doesn't get deleted. If I delete a Gallery or an Album it doesn't mean a Category disappears.
And once the Gallery is aware of the existence of a Category, it can select it and access any Album that also is associated with that Category whatever that Album is associated with. In this case Images through an Album_Images join table.
I also have an Album_Gallery jointable that may be being made redundant by the Category table, I'm not sure yet. I'm still trying to figure this out.
If this makes sense to you and you have some insight on how I could accomplish what I am going for here, please let me know.
1 thought on “Trying to understand multiple jointable through connections and how they work”
Your question is actually pretty complex. I assume you have your has_many and has_many :through associations in the model set up correctly. In the form, you can create the association with an “accepts attributes for” in the model section and then putting it in your form in the view.
There are ways that you can set it up so that it only deletes the record in the association table, and not any records on either end.
As for the active record part, you can map the results of one query in order to use those parameters to get the records you desire. For example. You can map the ids of the albums at certain galleries, and use the results to find the album images.
Hopefully that helped. If not, PM me your github repo and I can try to muddle my way through helping you.