Let’s say you have a one-to-many relationship between Users and Orders (where one user can have many orders). Is it possible to create a User object, add orders to it, and save it in one go? Or do you have to save the User object first so that an ID is generated before you can save the orders collection?
Let’s say you have a one-to-many relationship between Users and Orders (where one user
Share
I was able to solve this by using the “build” method. From the ActiveRecord::Associations::ClassMethods documentation: