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

[8.x] Guess relation name in model factories #33450

Merged
merged 1 commit into from
Jul 7, 2020
Merged

[8.x] Guess relation name in model factories #33450

merged 1 commit into from
Jul 7, 2020

Conversation

bastien-phi
Copy link
Contributor

@bastien-phi bastien-phi commented Jul 7, 2020

I think we could improve the way relationship are guessed.

Actually, the relationship is always pluralized and singular form of HasOne cannot be guessed. For example, a User having a has one subscription relation we always have to write
 

UserFactory::new()
    ->has(SubscriptionFactory::new(), 'subscription')
    ->create();

This PR resolves correctly the relation just doing

UserFactory::new()
    ->has(SubscriptionFactory::new())
    ->create();

I don't know if this should be used also on hasAttached method to be honest...

If this needs tests, I would be happy to add them.

@taylorotwell taylorotwell merged commit 7d78de0 into laravel:master Jul 7, 2020
@bastien-phi bastien-phi deleted the guess_relation_name_in_model_factories branch July 7, 2020 14:35
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.

2 participants