Explain how the reference()
helper function transforms the data
#10774
Labels
help wanted
Issues looking for someone to run with them!
improve or update documentation
Enhance / update existing documentation (e.g. add example, improve description, update for changes)
📚 Subject area/topic
Content Collections
📋 Page(s) affected (or suggested, for new content)
https://docs.astro.build/en/guides/content-collections/#defining-collection-references
https://docs.astro.build/en/guides/content-collections/#accessing-referenced-data
📋 Description of content that is out-of-date or incorrect
The documentation for the
reference()
utility function is lacking some info. From the description, I only assumed it adds type-safety to referenced items (possibly validating that an item with that ID exists, still not sure if it actually does that or if that's even technically possible). However, it also transforms the property.For example, if I define a property using the reference helper:
And then specify an ID in a collection item:
Now if I access that property, it's not a string any more, but an object containing both the collection and id:
This is what allows me to use
getEntry
without specifying a collection:I was surprised by this and actually thought there was a bug (withastro/astro#13052), because I didn't asume the
reference()
utility would transform the value of the property.Suggested improvements
reference()
function transforms the property to an object, and how to work with that in a templategetEntry
without specifying a collection because of the above-mentioned transforms. Right now, this is easy to miss in the code example.🖥️ Reproduction in StackBlitz (if reporting incorrect content or code samples)
No response
The text was updated successfully, but these errors were encountered: