Querying relations/associations #35

Open
opened 2016-11-03 07:14:46 +00:00 by labibramadhan · 4 comments
labibramadhan commented 2016-11-03 07:14:46 +00:00 (Migrated from github.com)

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'}} ?

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](http://docs.sequelizejs.com/en/latest/docs/querying/#relations-associations), 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'}}` ?
joeybaker commented 2016-11-03 17:29:31 +00:00 (Migrated from github.com)

@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!

@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!
labibramadhan commented 2016-11-04 03:15:11 +00:00 (Migrated from github.com)

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

![screen shot 2016-11-04 at 10 13 07 am](https://cloud.githubusercontent.com/assets/6038766/19993325/52e44b1c-a277-11e6-8990-3296f01e9f5e.png) @joeybaker, as i've mentioned, i think it doesn't work. seems like **include** parameter only accepts **string** or **array of string**
joeybaker commented 2016-11-04 03:24:07 +00:00 (Migrated from github.com)

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

@labibramadhan ah! that makes sense. It should accept an array of JSON strings and doesn't.
labibramadhan commented 2016-11-04 05:26:03 +00:00 (Migrated from github.com)

alright, i have created PR, please review @joeybaker

alright, i have created PR, please review @joeybaker
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: thereadme/hapi-sequelize-crud#35
No description provided.