Closed ThomasSmWatson closed 7 years ago
@ThomasSmWatson Unfortunately it is not currently possible to filter products by relationship on V2 of the API. This is not a limitation of this library. The best way to achieve this would be to get the category in question, and include the related products in the payload.
With the category ID:
Moltin.Categories.Get(id).With(['products'])
Or alternatively with the name/slug:
Moltin.Categories.All().Filter(
eq: {
slug: 'category-slug'
}
}).With(['products']);
The response payload will include a top level included
object with a products
array.
{
"data": {
// Your category record
},
"included": {
"products": [
// The related products
]
}
}
Filtering by relationships is functionality that will we introduce further down the product roadmap.
Hope this helps! 🙃
Uncaught TypeError: Moltin.Categories.Get(...).With is not a function
@GanchoDanailov Oops, the correct way to chain those methods:
Moltin.Categories.With('products').Get(id)
Hope this helps 😄
Previously in V1, you could filter products by Category; it seems you cannot do that now in the SDK. My current v1 implementation of moltin requires the capability to do this. I would prefer not to do this manually on my micro-service if possible