Giter Club home page Giter Club logo

Comments (9)

fionagithub avatar fionagithub commented on May 29, 2024 1

+1

from feathers-vuex.

marshallswain avatar marshallswain commented on May 29, 2024

Ah, yes. I haven't handled array responses. Thank you for spotting this. I'll probably be able to fix this over the weekend, unless you have the bandwidth to submit a PR. 🙏

from feathers-vuex.

fionagithub avatar fionagithub commented on May 29, 2024

what should i do to filter that progame catch this error

from feathers-vuex.

joakimglaving avatar joakimglaving commented on May 29, 2024

Is there any news on this? Based on @tommygarces digging, I've been trying to get it to call addOrUpdateList when the response is an array, but it seems I'm missing something else to make it work as intended.

This is what I tried:

return service.create(data).then(function (item) {
    if(item.length){
      dispatch('addOrUpdateList', item)
    }else{
      dispatch('addOrUpdate', item);
    }
    commit('setCurrent', item);
    commit('unsetCreatePending');
    return item;
  }).catch(function (error) {
    commit('setCreateError', error);
    commit('unsetCreatePending');
    return Promise.reject(error);
});

Everything is added to the db and I get no errors, but already in my backend after create hook, the PK id is null.

from feathers-vuex.

Torge avatar Torge commented on May 29, 2024

The only Problem I see in this is that 'addOrUpdateList' assumes the provided array is the complete list and will remove all items from the store that are not included in the provided array if autoRemove is turned on.
This is what you expect to happen if you dispatch 'find', but unsuitable if you dispatch an bulk request.

There should maybe be two different actions for bulk requests and find.

You could just dispatch 'addOrUpdate' for each item if the response is an array:

return service.create(data).then(function (item) {
  if (Array.isArray(item)) {
    item.forEach(function (item) {
      dispatch('addOrUpdate', item);
    });
  } else {
    dispatch('addOrUpdate', item);
  }
  commit('setCurrent', item);
  commit('unsetCreatePending');
  return item;
}).catch(function (error) {
  commit('setCreateError', error);
  commit('unsetCreatePending');
  return Promise.reject(error);
});

from feathers-vuex.

joakimglaving avatar joakimglaving commented on May 29, 2024

@Torge thanks for the suggestion, however even when doing it that way, the id = null for the returned items.

from feathers-vuex.

Torge avatar Torge commented on May 29, 2024

@bobcat1 sorry i looked at your original issue just now, but it seems like this issue in this thread is dealing with the problem of not handeling the response of bulk 'create' as specified here https://docs.feathersjs.com/api/services#createdata-params
data may also be an array.

Your Problem seems to be, not having an unique single id.

from feathers-vuex.

joakimglaving avatar joakimglaving commented on May 29, 2024

@Torge This issue is not related to #67.

My use case in relation to this specific issue is:
I'm trying to add an array of items, and then I need to use the IDs returned to add more items, based on the IDs returned from the first array. It's just that all IDs are null when returned. So my workaround right now is to make a find call after they have all been added. That way I get all the IDs, and can use them to add the rest of my data.

from feathers-vuex.

marshallswain avatar marshallswain commented on May 29, 2024

This is fixed in the latest pre-release. npm i feathers-vuex@pre, and it will be included in the next minor version.

from feathers-vuex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.