Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] fix: Factory::createMany creating n^2 records #51225

Merged
merged 2 commits into from
Apr 30, 2024

Conversation

calebdw
Copy link
Contributor

@calebdw calebdw commented Apr 26, 2024

Hello!

Closes #51224

This PR fixes the N^2 issue when using EloquentFactory::createMany with a count. I went with Option 1 given in the issue, so passing an argument to createMany will overwrite any previous count set on the model---leaving the arg null will use the count set on the model.

User::factory()->count(2)->createMany(); // 2 records created
User::factory()->count(2)->createMany([['foo' => 1], ['foo' => 2], ['foo' => 3]]); // 3 records created

If you'd like me to change the behaviour for that one edge case, just let me know!

Thanks!

@calebdw calebdw changed the title [10.x] fix: Factory::createMany creating n+1 records [10.x] fix: Factory::createMany creating n^2 records Apr 26, 2024
@taylorotwell taylorotwell merged commit 44dba84 into laravel:11.x Apr 30, 2024
28 checks passed
@calebdw
Copy link
Contributor Author

calebdw commented Apr 30, 2024

Thanks @taylorotwell!

@calebdw calebdw deleted the factory_times branch April 30, 2024 12:55
@GrahamCampbell GrahamCampbell changed the title [10.x] fix: Factory::createMany creating n^2 records [11.x] fix: Factory::createMany creating n^2 records Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

N^2 models created when using EloquentFactory::createMany in conjunction with a count
2 participants