createManyQuietlyRelation<TRelated extends Model<TRelated>> method

Future<List<TRelated>> createManyQuietlyRelation<TRelated extends Model<TRelated>>(
  1. String relationName,
  2. List<Object> attributesList
)
inherited

Creates multiple related models without firing model events.

Same as createManyRelation but bypasses model event dispatching. No creating/created/saving/saved events are fired during insertion.

Each item in attributesList accepts:

  • A tracked model instance (TRelated).
  • An InsertDto or UpdateDto instance.
  • A Map<String, Object?> containing field/column values.

Example:

final author = await Author.query().find(1);
final posts = await author.createManyQuietlyRelation<Post>('posts', [
  {'title': 'Post 1', 'published_at': DateTime.now()},
  {'title': 'Post 2', 'published_at': DateTime.now()},
]);

// Using DTOs:
final posts2 = await author.createManyQuietlyRelation<Post>('posts', [
  PostInsertDto(title: 'DTO 1', publishedAt: DateTime.now()),
  PostInsertDto(title: 'DTO 2', publishedAt: DateTime.now()),
]);

Implementation

Future<List<TRelated>> createManyQuietlyRelation<
  TRelated extends Model<TRelated>
>(String relationName, List<Object> attributesList) async {
  if (attributesList.isEmpty) return [];

  final results = <TRelated>[];
  for (final attributes in attributesList) {
    results.add(
      await createQuietlyRelation<TRelated>(relationName, attributes),
    );
  }

  return results;
}