Giter Site home page Giter Site logo

Comments (2)

cuebit avatar cuebit commented on May 27, 2024

While this isn't an issue with the axios plugin per-se, it seems to point to either Vuex ORM or json-api-response-converter.

Currently a morphTo relation expects the id and type to exist in the given record since it doesn't need to attach foreign keys to the related model. Given your transformed data doesn't provide that, the necessary relations are not generated. For example, the following payload will generate the relations for a morphTo:

Activity.insert({
  data: {
    id: 'a1',
    causer_id: 'u1',
    causer_type: 'users',
    causer: { id: 'u1', name: 'Admin' }
  }
})

I'm not sure if this is Vuex ORM just not generating the missing foreign keys (something @kiaking could shed light on perhaps?)... But As a workaround, you could attach the would-be foreign keys to the Activity model in the transformer:

static apiConfig = {
  dataTransformer: (response) => {
    const data = new JsonApiResponseConverter(response.data).formattedResponse

    data.forEach((item, index) => {
      if (item.causer) {
        data[index].causer_id = item.causer.id
        data[index].causer_type = 'users'
      }
      if (item.subject) {
        data[index].subject_id = item.subject.id
        data[index].subject_type = 'institutes'
      }
    })

    return data
  }
}

Here's a workable fork.

from plugin-axios.

yoelpc4 avatar yoelpc4 commented on May 27, 2024

Thanks for responding my issue @cuebit, the reason why I'm asked here instead of on vuex-orm package, is because of the dataTransformer timing so that I can provides data with expected morph to format.

This case is using User as causer and Institute as subject, anyway how can I guess the type of related data if I have registered 44 models on vuex-orm database?

Another point to mention is JSON:API prefers kebab-case on resource's type, but vuex-orm prefers snake-case on model's entity. Should I make a morph map to solve this case?

from plugin-axios.

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.