vuex-orm-next icon indicating copy to clipboard operation
vuex-orm-next copied to clipboard

Heterogenous data lists

Open innovate-invent opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe...

The backend I interact with returns a heterogenous list of objects. This can't currently be processed by VuexORM. Each object has an attribute declaring its type.

{
  "type":"container",
  "elements": [
    { "id": 1, "type":"type1", "type1param":"", "common_param":"" },
    { "id": 2, "type":"type1", "type1param":"", "common_param":"" },
    { "id": 3, "type":"type2", "type2param":"", "common_param":"" },
  ]
}

or simply a fetch response can be

[
  { "id": 1, "type":"type1", "type1param":"", "common_param":"" },
  { "id": 2, "type":"type1", "type1param":"", "common_param":"" },
  { "id": 3, "type":"type2", "type2param":"", "common_param":"" },
]

Describe the solution you'd like

Provide a relation that keys on the object type attribute and handles it accordingly. The relation should accept a mapping of type attribute values to ORM models.

Describe alternatives you've considered

I am currently transforming the data using a request hook to split the lists.

innovate-invent avatar Apr 14 '20 18:04 innovate-invent

@innovate-invent Thanks for the feedback! Yes, currently the "morph" relations are not implemented yet at this repo. I think once that's implemented, this should be possible too.

kiaking avatar Apr 15 '20 08:04 kiaking

I've opened #90 for MorphOne relation.

kiaking avatar Nov 01 '21 10:11 kiaking

@kiaking I am not sure the morphone relationship allows for what I am describing. MorphOne seems to allow an item to backreference a variable type, where I need to be able to deserailize a list of varying types.

Am I misunderstanding how to do that with MorphOne as it exists?

innovate-invent avatar Nov 14 '21 05:11 innovate-invent

@innovate-invent Ah sorry, yes MorphOne is not exactly what you're looking for. However, we're working on implementing all Polymorphic relation like MorphTo and MorphMany and such so eventually you'll get what you want! Stay tuned 👍

kiaking avatar Nov 15 '21 03:11 kiaking

Would you mind reopening this to ensure it isn't overlooked? I should point out that this type of relation wasn't available in the previous version either.

innovate-invent avatar Nov 15 '21 04:11 innovate-invent