GithubHelp home page GithubHelp logo

Understanding polymorphism about data HOT 2 CLOSED

Jopie01 avatar Jopie01 commented on June 1, 2024
Understanding polymorphism

from data.

Comments (2)

Jopie01 avatar Jopie01 commented on June 1, 2024

OK, digged a bit deeper through the code and specifically https://github.com/emberjs/data/blob/5a48f52a08587e59cb529575577880daf678ae00/packages/store/src/-types/q/schema-service.ts the last portion. As it turns out I have the polymorphic: true at the wrong level. It should be in the options

menu model:
{
  action: {
    name: 'action',
    kind: 'belongsTo',
    options: {
        polymorphic: true,
        async: true,
        inverse: null
    }
  }
}

Seems like I don't have to specify a type because with this I'm able to push data into the store and then I can happily request it from the store without errors. The only extra thing I have to do is to make sure the models exists when data is pushed, so first fetch the model before pushing into the store.

from data.

runspired avatar runspired commented on June 1, 2024

For inverse: null yes, there is nothing additionally needed though you are missing the abstract type and should make sure you include it.

{
  action: {
    name: 'action',
    kind: 'belongsTo',
+   type: 'action', // I'm guessing here that the abstract type is also "action"
    options: {
        polymorphic: true,
        async: true,
        inverse: null
    }
  }
}

For inverse: <some-prop> the corresponding field on the other record must specify the abstract type. So for instance, assume menu said this:

{
  action: {
    name: 'action',
    kind: 'belongsTo',
+   type: 'action',
    options: {
        polymorphic: true,
        async: true,
+       inverse: 'lists'
    }
  }
}

Then any record that satisfies "action" must have the below field def:

// "add-item" action
{
  lists: {
    name: 'lists',
    kind: 'hasMany',
    type: 'menu',
    options: {
      async: true,
      inverse: 'action',
      as: 'action'
    }
  }
}

as here is what allows any type to act as the abstract type. Note, the entire field configuration must identically match across all types that satisfy this polymorphic trait.

from data.

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.