hapi-sequelize-crud icon indicating copy to clipboard operation
hapi-sequelize-crud copied to clipboard

Querying relations/associations

Open labibramadhan opened this issue 8 years ago • 4 comments

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 avatar Nov 03 '16 07:11 labibramadhan

@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 avatar Nov 03 '16 17:11 joeybaker

screen shot 2016-11-04 at 10 13 07 am

@joeybaker, as i've mentioned, i think it doesn't work. seems like include parameter only accepts string or array of string

labibramadhan avatar Nov 04 '16 03:11 labibramadhan

@labibramadhan ah! that makes sense. It should accept an array of JSON strings and doesn't.

joeybaker avatar Nov 04 '16 03:11 joeybaker

alright, i have created PR, please review @joeybaker

labibramadhan avatar Nov 04 '16 05:11 labibramadhan