fix populate depth and infinite recursion for Collection Links #1459
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #1450
What is this about?
When using
?populate=1
,?populate=2
, etc. when querying a collection with collectionlink fields, the populate query value also doubles as a max depth parameter. However, the index is off by 1, meaning that?populate=1
will populate 2 depths and?populate=0
will not populate anything meaning that it is currently impossible to populate only a depth of 1.The issue is most apparent when you have a cyclical relationship between two collections. When you enable
populate
, it will automatically fillA->B->A
instead of justA->B
Before
?populate=0
gives:{"a": {link}}
{"a": {"b": {link}}}
?populate=1
gives:{"a": {"b": {"a": {link}}}}
After
?populate=0
gives:{"a": {link}}
?populate=1
gives:{"a": {"b": {link}}}
?populate=2
gives:{"a": {"b": {"a": {link}}}}
What this PR does:
It updates the logic of the populate function so that the value that the user passes actually aligns with the depth that they want to populate
Additionally, this also fixes infinite recursion for cyclical collections when
?populate=-1
by tracking the_id
andcollection
values when populating.Example Outputs using this PR:
Relationships:
Example Setup
Setup collections:
Setup entries:
sample
docker-compose.yml