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

[9.x] Allow factories to recycle models with for method #44265

Merged
merged 4 commits into from
Sep 23, 2022

Conversation

jessarcher
Copy link
Member

This PR addresses #44107 (comment) where using the Factory for method instead of specifying a 'model_id' => Model::factory() definition does not use recycled models. I think this makes sense, although typically you'd call for from your test where you could just pass the model directly, so I think it's more of an edge case.

I considered adding support for the has method as well, however, I don't think that one makes as much sense. If the recycled model belongs to another model, then I don't think it's parent relationship should be re-assigned, especially if it's part of a has many relationship where more than one model might be needed. I could make it attach the model in a many-to-many relationship, but it would probably need to be conditional on whether one or many models were requested. In any case, I can't think of a scenario where this would be a papercut so I'm not inclined to look into it further right now.

@jessarcher
Copy link
Member Author

I wasn't too keen on making the recycle property public as it doesn't match the other properties. But I thought it might also be overkill to create a public method to access it.

@taylorotwell taylorotwell merged commit d58c89f into 9.x Sep 23, 2022
@taylorotwell taylorotwell deleted the factory-recycle-for branch September 23, 2022 14:06
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