You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I want to reference a collection item in a property from another collection. I have defined the property crops using the reference helper, as documented in Defining collection references:
schema: z.object({crop: reference('crops'),}),
Then in my content items (JSON files using the glob loader in this case), I reference an item from the crops collection by ID:
{
"crop": "grapevine"
}
Now I want to load the grapevine collection item in a template:
const{ region }=Astro.props;constcrop=awaitgetEntry('crops',region.data.crop)!;
This is giving me type warnings, and it doesn't return the collection item:
Typehint tells me that region.data.crop is an object with keys collection and id. Therefore, I tried to access the ID, this works correctly and gets rid of the type warnings:
const{ region }=Astro.props;constcrop=awaitgetEntry('crops',region.data.crop.id)!;
Is the reference helper supposed to transform the reference into an object like this?
I'm not sure if this is a bug or if the documentation is just outdated. The documentation on Accessing referenced data only shows using the property key, not accessing a nested id property.
What's the expected result?
Not sure if the documentation needs to be updated, or the behaviour I'm seeing is a bug.
Link to Minimal Reproducible Example
Not applicable.
Participation
I am willing to submit a pull request for this issue.
The text was updated successfully, but these errors were encountered:
It would be useful to mention in the docs that the reference() helper transforms the property, I don't think this is documented anywhere. I've opened an issue on that: withastro/docs#10774
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I want to reference a collection item in a property from another collection. I have defined the property
crops
using thereference
helper, as documented in Defining collection references:Then in my content items (JSON files using the
glob
loader in this case), I reference an item from thecrops
collection by ID:Now I want to load the
grapevine
collection item in a template:This is giving me type warnings, and it doesn't return the collection item:
Typehint tells me that
region.data.crop
is an object with keyscollection
andid
. Therefore, I tried to access the ID, this works correctly and gets rid of the type warnings:Is the
reference
helper supposed to transform the reference into an object like this?I'm not sure if this is a bug or if the documentation is just outdated. The documentation on Accessing referenced data only shows using the property key, not accessing a nested
id
property.What's the expected result?
Not sure if the documentation needs to be updated, or the behaviour I'm seeing is a bug.
Link to Minimal Reproducible Example
Not applicable.
Participation
The text was updated successfully, but these errors were encountered: