Rails 6.1 has added support for bulk insertion for associations.
Previously, bulk insertion for associations did not work as expected.
Before Rails 6.1
Rails 6.0 has added support in ActiveRecord for bulk record insertion which works similar to update_all.
It provides methods like insert_all, insert_all!, upsert_all etc for the bulk creation.
We can do bulk insert in a table as:
It will create 2 records for Address.
Now, if we try to create multiple records using an association as below:
It creates 2 address records but not for this user. We can see that the same query is fired in both cases.
In both cases, multiple records are getting created but the association is ignored in the second example.