Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Nested media is only showing image ids array.

default discord avatar
mirus.studio4 weeks ago
1

Hi! I'm really struggling with making this work in one Local API call.



My structure is simple:

· products -> joined with product-variants


·· product-variants -> has "images" upload field with relationTo "media" collection


··· media




No matter what I do, which select fields I add, which populate fields I add or what depth I set on payload.find() that I'm able to see full media image object (with filename, sizes, url...etc).



The only way I've managed to do it is by getting all of product-variants ids, then mapping over them to fetch each image by its id (which they do appear in the images array), then merging all objects.



Also, when I was doing this looping approach, if I added "select" object to only get "filename" and "sizes" objects, for example, now "images" array would be empty; not even image ids.




I don't know if I'm missing anything but I can assure that I've tried 200 different things and I still can't get it to work as it should.



It shouldn't be this hard to fetch this kind of nested objects 🫤



In case someone has the same problem, I found the problem. I feel too dumb for wasting so much time for a single line, but here it is the solution:



- For "join" fields, maxDepth is defaulted to 1, which did not allow nested images object to be fetched regardless of the "depth" you set in the Local API call.

    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.