diff --git a/src/masoniteorm/scopes/UUIDPrimaryKeyScope.py b/src/masoniteorm/scopes/UUIDPrimaryKeyScope.py index ef091de7..00f814ad 100644 --- a/src/masoniteorm/scopes/UUIDPrimaryKeyScope.py +++ b/src/masoniteorm/scopes/UUIDPrimaryKeyScope.py @@ -1,4 +1,5 @@ import uuid + from .BaseScope import BaseScope @@ -9,6 +10,9 @@ def on_boot(self, builder): builder.set_global_scope( "_UUID_primary_key", self.set_uuid_create, action="insert" ) + builder.set_global_scope( + "_UUID_primary_key", self.set_bulk_uuid_create, action="bulk_create" + ) def on_remove(self, builder): pass @@ -22,15 +26,21 @@ def generate_uuid(self, builder, uuid_version, bytes=False): return uuid_func(*args).bytes if bytes else str(uuid_func(*args)) + def build_uuid_pk(self, builder): + uuid_version = getattr(builder._model, "__uuid_version__", 4) + uuid_bytes = getattr(builder._model, "__uuid_bytes__", False) + return { + builder._model.__primary_key__: self.generate_uuid( + builder, uuid_version, uuid_bytes + ) + } + def set_uuid_create(self, builder): # if there is already a primary key, no need to set a new one if builder._model.__primary_key__ not in builder._creates: - uuid_version = getattr(builder._model, "__uuid_version__", 4) - uuid_bytes = getattr(builder._model, "__uuid_bytes__", False) - builder._creates.update( - { - builder._model.__primary_key__: self.generate_uuid( - builder, uuid_version, uuid_bytes - ) - } - ) + builder._creates.update(self.build_uuid_pk(builder)) + + def set_bulk_uuid_create(self, builder): + for idx, create_atts in enumerate(builder._creates): + if builder._model.__primary_key__ not in create_atts: + builder._creates[idx].update(self.build_uuid_pk(builder))