fix populate depth and infinite recursion for Collection Links#1459
Open
beasteers wants to merge 2 commits intoagentejo:nextfrom
Open
fix populate depth and infinite recursion for Collection Links#1459beasteers wants to merge 2 commits intoagentejo:nextfrom
beasteers wants to merge 2 commits intoagentejo:nextfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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=1will populate 2 depths and?populate=0will 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->Ainstead of justA->BBefore
?populate=0gives:{"a": {link}}{"a": {"b": {link}}}?populate=1gives:{"a": {"b": {"a": {link}}}}After
?populate=0gives:{"a": {link}}?populate=1gives:{"a": {"b": {link}}}?populate=2gives:{"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=-1by tracking the_idandcollectionvalues when populating.Example Outputs using this PR:
Relationships:
Example Setup
Setup collections:
Setup entries:
sample
docker-compose.yml