-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.3] Fix database factory error when zero is provided #15764
Conversation
👍 |
I'm more curious in why when you pass zero before you would get models? |
@taylorotwell I think because
|
@taylorotwell because passing |
Would it better to just return an empty Collection instead of throw an exception? |
@taylorotwell yeah i think that will be better. |
@taylorotwell Code updated. An empty collection is returned instead of exception. |
I think the real question is why would you use factory with 0? I mean calling a factory method with 0 will never return any models so it's not logic to call it with 0 right? |
Wow, holy man you guys are super duper quick on issues! I figured I'd check back in next week to see if any cared about fixing such a minor issue, but you guys got on it within hours. @bobbybouwmann The story goes I wanted to generate a random number of dependent records for a set of given parent records. The random range was 0 to 15 children per parent record. I noticed that my Don't ask me why I did it this way. I was working on a project as fast as I could go and this is what I ended up producing. $parents = factory(App\Parent::class, 5)->create();
$parents->each(function ($parent) {
$random = rand(0, 15);
if ($random <= 1) {
$parent->dependants()->save(factory(App\Dependant::class, $random)->make());
}); results in
|
@etherealite Why don't you try this. May fix your issue.
|
Thanks for the tip @srmklive. I solved the issue by making a check This is just experimental code, so I can be as dirty as I would like. Again, I'm super impressed by the responsiveness and eagerness to contribute displayed in this community. |
Fixes #15755