Skip to content

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

Merged
taylorotwell merged 4 commits into
9.xfrom
factory-recycle-for
Sep 23, 2022
Merged

[9.x] Allow factories to recycle models with for method#44265
taylorotwell merged 4 commits into
9.xfrom
factory-recycle-for

Conversation

@jessarcher

Copy link
Copy Markdown
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
Copy Markdown
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.

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