[2.0] Recursion error when factory creates relationship on itself
Opened this issue · 3 comments
TestDummy is unable to handle creating a dummy record when the record requires a mock of itself for a relationship.
An example:
A User model can must be created by a user (think of a customer relationship management system, a new customer contact record is created, but the business wants to log who has created, or owns that user account).
The following code can be used to replicate the issue:
$factory('App\User', [
'uuid' => $faker->uuid,
'name' => $faker->name,
'email' => $faker->email,
'created_by_id' => 'factory:App\User'
]);
Ideally, if there is only one User being created that has a self relationship, it should set the id the the id that has been inserted.
What happens when you run this? I would think it would allow that...
Ahh, yeah didn't see the title of this issue. Yeah, there would be a recursion issue, wouldn't there...
Hmm - I'll take a look.
Perhaps I'm wrong but couldn't the created_by_id just reference a different App\User factory that has been name-spaced to something like UserCreator? In the UserCreator factory just leave the created_by_id field blank?