Follow-up from "Introduce support for bulk-inserting model associations"
The following discussions from !25591 (merged) should be addressed:
-
@ayufan started a discussion: This exception description is not fully accurate, as:
- we test effectively
primary_id
orforeign_id
,
This exception would be raised in two cases:
-
primary_key
is missing, -
attributes['id']
(lets assume thatprimary_key=id
) is not set.
Maybe we should change the
primary_key
to beforeign_id
and update the message to be descriptive to cover these two cases. - we test effectively
-
@ayufan started a discussion: It seems that to be fully correct we need to improve
primary_id =
to be, ashas_many
can define:primary_key
.raise "Classes including `BulkInsertableAssociations` must define a `primary_key`" unless self.active_record_primary_key primary_id = public_send(self.active_record_primary_key) raise "Dependent associations can be bulk inserted only when `primary_id` is set" unless primary_id
-
@ayufan started a discussion: Do we need to truncate all other tables?
-
@ayufan started a discussion if attributes.delete(primary_key)
raise PrimaryKeySetError, "Primary key set: #{primary_key}:#{attributes[primary_key]}\n"
"Bulk-inserts are only supported for rows that don't already have PK set" endthis raise seems to not be working properly (as for message), as we delete key first, and then it is no longer part of attribute