Skip to content

[12.x] Be more specific about usage of recycle() #10377

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

Closed
wants to merge 2 commits into from

Conversation

bertheyman
Copy link
Contributor

Recycle only works for relationships defined inside of the factory.
This PR makes that more clear in the docs, and refers to the hasAttached section for many-to-many relationships.

bertheyman added 2 commits May 7, 2025 15:08
Be specific about recycle only working for 1-1 and 1-many
@bertheyman bertheyman changed the title Be more specific about usage of recycle() [12.x] Be more specific about usage of recycle() May 7, 2025
@@ -1,4 +1,4 @@
# Eloquent: Factories
one# Eloquent: Factories
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure, the "one" is supposed to be there?

Comment on lines +619 to +620
For factories that include relationships, you may use the `recycle` method to ensure a single instance of the related model is recycled for all of the relationships created by the factory.
For relationships outside of the factory (like a many-to-many), see [HasAttached()](#pivot-table-attributes).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the first part is needed since we are already on the "Factories" docs page. Furthermore, I'd assume, you would need yet another line break to make Markdown render the second part as a separate paragraph.

@taylorotwell
Copy link
Member

Going to skip this one for now.

@bertheyman
Copy link
Contributor Author

If you have models that share a common relationship with another model, you may use the recycle method to ensure a single instance of the related model is recycled for all of the relationships created by the factory.

@taylorotwell @shaedrich
I feel the current explanation isn't fully clear: a many-to-many relationships can also be created by the factory, and will not respect recycle(). Would you like me to tweak the wording for this PR, or drop it altogether?

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.

3 participants