Say i have a category ‘fiction’, that has a reference to many, for different ‘books’. I create the category and reference many different books inside the category.
How do i go about making a filter view to grab only the ‘books’ in the reference list, inside the ‘fiction’ category entry?
I don’t know if i’m missing something as i’m new to contentful, but the only way I can get this to work is to make a reference to one entry from the ‘book’ to the ‘fiction’ category. Then i can get all books and filter from their reference. This seems a backwards way to do it though.
Which SDK are you using? Or are you calling the API directly? If using the JS SDK, you can simply get the ‘fiction’ category entry and all the referenced books will get retrieved at the same time. Go to this link to see this snippet:
const contentful = require('contentful')
const client = contentful.createClient({
space: '<space_id>',
environment: '<environment_id>', // defaults to 'master' if not set
accessToken: '<content_delivery_api_key>'
})
client.getEntry('<entry_id>')
.then((entry) => console.log(entry))
.catch(console.error)
If the model was reversed (books point to the fiction category) then you could make a saved view, but the model as you’ve described won’t work with a saved view.