Seed Resources with many-to-many relationships

Hello, I want to seed resources with many-to-many relationships. How would I accomplish this? I am thinking of doing something silly, just reference the rows that were inserted, considering that I don't know the actual IDs, and then read them appropriately and bulk-create them. Any ideas are welcome!
Solution:
changeset generators. ended up doing what I said above, I basically created my own structs with the indices that I am interested in, and then just used Enum.at(foos, foo_index) to create the correct references. I also had to make the relationships on the many-to-many public so that I can create them. Anywho, thanks for the help!...
Jump to solution
2 Replies
ZachDaniel
ZachDaniel2mo ago
You should be able to seed with related structs. Are you using changeset generators or seed generators?
Solution
theopechli
theopechli2mo ago
changeset generators. ended up doing what I said above, I basically created my own structs with the indices that I am interested in, and then just used Enum.at(foos, foo_index) to create the correct references. I also had to make the relationships on the many-to-many public so that I can create them. Anywho, thanks for the help!

Did you find this page helpful?