New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use entries() with linked entry IDs? #14
Comments
When you query and set the client.entries({
// filters
include: 1 // 1 up to 10 levels of resolved includes
}).then(function(entries) {
// use entries, e.g., if the first entry had a link in fields.linkToOtherEntry:
console.log(entries[0].fields.linkToOtherEntry['en-US'].fields);
// -> { ... } fields of linked entry
}); |
Ah, nice. Thanks! |
Sorry, have to re-open. How do I actually filter the results by category in this example? Downloading the whole data set would not work for us in all cases, and it seems the API supports it in general, right? |
Hi @skddc, if I understand your use-case correctly you have two content types which are linked and you want to read all entries of content type A which has a reference to a content type B and where the values of content type B matches a certain constraint, right? Please note that such queries are currently not possible. What you can do though, is to read the wanted entry of content type B you are interested in and afterwards read all the entries of content type A which have Or in code (and with categories/entries): client
.entries{{ "content_type": "CategoryID", "fields.someField": "someValue" })
.then(function (category) {
return client
.entries({ "content_type": "EntryId", "fields.Category": category.sys.id })
.then(function (entries) {
// work with entries and/or category
// you could also: return Bluebird.join(category, entries)
});
}); |
Going for another interptetation: If you want to get all Entries of type A which are in a certain category if type B this should work: client.entries({
include: 1,
'fields.linkToCategoryOfTypeB.sys.id': 'idOfCategory'
}); As @sdepold said, you can't query for properties within the category, but you can still look for entries that link to a certain category ID. |
@ehd Thanks, that was exactly what I was looking for! |
🎉 |
@ehd do you know if that's changed yet? I'd like to be able to query by associated category name without doing the intermediate request for the categories. |
Someone please correct me if I'm wrong (cc @sdepold). @asross It works the same as far as I know. What I do is keep a map from category names to IDs in a config file in my code so I can query by name. If your list isn't static, I would fetch the list at start up time, cache it and use that. I hope you find this helpful. |
cc @trodrigues :D |
Whoops. Thanks 😄 |
How can I use
client.entries()
with linked entry fields?See https://support.contentful.com/hc/en-us/articles/200513278-How-do-I-add-categories-to-my-content-?page=1#comment_202252446 for use case.
The text was updated successfully, but these errors were encountered: