Creating multiple records using service.create(data) with an array yields: no id error
See original GitHub issueWhen dispatching create action on a service with an array of multiple objects as data:
var data = [
{name: 'index', permissions: 'guest'},
{name: 'about', permissions: 'guest'},
{name: 'admin', permissions: 'superuser'}
]
store.dispatch('/pages/create', data)
, the following error appears:
Error: No id found for item. Do you need to customize the `idField`?
The data is succesfully added to the database. The problem is when the promise is returned to the action and sent to the addOrUpdate action.
Upon analyzing the create action in src/service-module/actions.js, it seems that the error is produced by treating the response of the service.create(data) as a single object and passing that to addOrUpdate instead of addOrUpdateList:
create ({ commit, dispatch }, data) {
commit('setCreatePending')
return service.create(data)
.then(item => {
dispatch('addOrUpdate', item)
commit('setCurrent', item)
commit('unsetCreatePending')
return item
})
.catch(error => {
commit('setCreateError', error)
commit('unsetCreatePending')
return Promise.reject(error)
})
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Creating multiple records using service.create(data) with an ...
When dispatching create action on a service with an array of multiple ... using service.create(data) with an array yields: no id error #61....
Read more >Order of returned Ids when creating multiple records with the ...
When I create records using the SOAP API, the Id of the created records are returned, and if multiple records are created in...
Read more >Not able to delete multiple records from database having array ...
I have a service.ts file that calls HTTP Client method to delete multiple records from db. But when I'm passing multiple Id's in...
Read more >Create Multiple Records with Fewer Round-Trips
You can't create records for multiple object types in one call when one of the types is related to a feature in the...
Read more >5. Working with Arrays and Loops - JavaScript Cookbook [Book]
Not all array elements have to be defined when created. For instance, if you create an array literal, you can use commas to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1
This is fixed in the latest pre-release.
npm i feathers-vuex@pre
, and it will be included in the next minor version.