hapi-sequelize-crud
hapi-sequelize-crud copied to clipboard
Querying relations/associations
I have 2 models:
- product with 1 field: name
- category with 1 field: name
Association is:
- product belongsTo category
The problem is:
When i try to GET /api/v1/products?name[category]=Category 1
it outputs val.replace is not a function error
But according to sequelize documentation on here, the way of querying relations/associations is by using its include parameter and then append its where parameter inside.
Maybe you could allow the current include parameter to accept object kind of:
include[]={model: 'category', where:{name: 'Category 1'}}
?
@labibramadhan hmmm… the latter suggestion, ?include[]={"model": "category", "where":{"name": "Category 1"}}
should work. Just make sure you're sending valid JSON. Let me know if it doesn't work!
@joeybaker, as i've mentioned, i think it doesn't work. seems like include parameter only accepts string or array of string
@labibramadhan ah! that makes sense. It should accept an array of JSON strings and doesn't.
alright, i have created PR, please review @joeybaker