Is recycle
method from factory random?
#53027
Unanswered
Barbapapazes
asked this question in
Q&A
Replies: 1 comment
-
Yes, it looks like the models are taken at random from the recycle collections in the factory. public function getRandomRecycledModel($modelClassName)
{
return $this->recycle->get($modelClassName)?->random();
} I think creating models where unique constraints are necessary is a fairly common use case, i tend to code around it in the seeders by generating a I'd propose that the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello 👋,
There is something I'm not understanding with the
recycle
method.With the following code, I expect that the first reaction to be post=1, emoji=1, user=1, then post=1, emoji=1, user=2 (or something like this but at the end, a predictable sequence where the recycle loop over small collections).
But, I've this in my database:
Which is clearly not a predictable sequence.
My issue is that I have the following SQL rule:
And the randomness cause SQL unique constraint to fail during seeding.
How could I solve this issue?
Beta Was this translation helpful? Give feedback.
All reactions