Skip to content

Update documentation for extra lazy associations - #12584

Open
diegobanos wants to merge 1 commit into
doctrine:3.6.xfrom
diegobanos:patch-1
Open

Update documentation for extra lazy associations#12584
diegobanos wants to merge 1 commit into
doctrine:3.6.xfrom
diegobanos:patch-1

Conversation

@diegobanos

Copy link
Copy Markdown

Clarified conditions for using Collection methods with extra lazy associations that won't initialize the Collection.

I was running some manual tests locally and it seems like EXTRA_LAZY collections get initialized when calling Collection::get() and Collection::containsKey() unless an indexBy field is specified. This wasn't clear in the docs.

Clarified conditions for using Collection methods with extra lazy associations that won't initialize the Collection.
@greg0ire

Copy link
Copy Markdown
Member

unless

🤔 did you mean to write "only if"?

Can you show me the tests you ran and the outcome, so that I understand better what you mean?

@diegobanos

Copy link
Copy Markdown
Author

unless

🤔 did you mean to write "only if"?

Can you show me the tests you ran and the outcome, so that I understand better what you mean?

I was reading this documentation page and comparing how LAZY and EXTRA_LAZY associations behave to understand it better. The tests were simply to call each method on a LAZY and an EXTRA_LAZY collection, and then inspecting if the collection became initialized or not. When testing the EXTRA_LAZY collection, I was surprised that calling Collection#containsKey($key) or Collection#get($key) would initialize the collection. I then found out that if I defined an indexBy to the EXTRA_LAZY collection, it was accurate that those two methods wouldn't initialize the entire collection.

The reason I submitted this MR is because I am assuming this is expected behavior but it was just not clear (to me) when reading the docs that this is how EXTRA_LAZY collections behave, and I wanted to help future readers. If this is unexpected behavior, I can create a small reproducible of this.

@diegobanos

Copy link
Copy Markdown
Author

🤔 did you mean to write "only if"?

Yeah, I think I said the opposite of what I meant to say... Having an indexBy defined on the EXTRA_LAZY collection is a requirement for Collection#containsKey($key) or Collection#get($key) to not initialize the entire collection.

@greg0ire

Copy link
Copy Markdown
Member

I think it's expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants