vuex-orm-next
vuex-orm-next copied to clipboard
Heterogenous data lists
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 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.
I've opened #90 for MorphOne relation.
@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 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 👍
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.