You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the Individual Factory it actually creates two Individual records, both of which are bound to the same user. This is because there is a UserObserver that creates a new individual record when a user is created with the individual context. The user only supports a hasOne relationship to the Individual. This means that one of the Individual records won't be accessible through it. Which causes issues when the Individual Factory is used in tests, which we tend to have to work around by getting the Individual through the user.
To Reproduce
Steps to reproduce the behavior:
use tinker php artisan tinker
run Individual::factory()->create();
look in the database and notice that there are two Individual records created both pointing at the same user id
Expected behavior
Using the Individual factory should only create the requested number of Individual records, all tied to a unique user record.
Screenshots
No response
Details
Device:
Operating system:
Browser:
Link to affected page:
Additional context
Options to consider for fixing:
The UserObserver shouldn't create a new Individual record if the user account is already bound to an Individual record
The user account may be created before the Individual from the factory. If that's the case, this will be too late to check if a second Individual will be created.
The individual factory shouldn't create an Individual directly, but rather defer to the one created via a user with the individual context. Then update the individual data with the values passed into the factory, and return the updated individual.
The text was updated successfully, but these errors were encountered:
Prerequisites
Describe the bug
When using the Individual Factory it actually creates two Individual records, both of which are bound to the same user. This is because there is a UserObserver that creates a new individual record when a user is created with the
individual
context. The user only supports ahasOne
relationship to the Individual. This means that one of the Individual records won't be accessible through it. Which causes issues when the Individual Factory is used in tests, which we tend to have to work around by getting the Individual through the user.To Reproduce
Steps to reproduce the behavior:
php artisan tinker
Individual::factory()->create();
Expected behavior
Using the Individual factory should only create the requested number of Individual records, all tied to a unique user record.
Screenshots
No response
Details
Additional context
Options to consider for fixing:
The text was updated successfully, but these errors were encountered: