Hi,
I have 3 models: Node, Document and Folder. Node model is polymorphic, it can be either Document or Folder.
Now, server side provides an endpoint /api/nodes/<node_id>/
which returns an array of nodes i.e. an array of objects, each being of type either “folders” or “documents”.
I push incoming data into the store as follows:
url = this.buildURL('nodes', node_id);
nodes = await fetch(url, {
method: 'GET',
headers: this.headers
}).then(response => response.json());
node_ids = nodes.data.map(node => {
let normalized_node = this.store.normalize('node', node);
this.store.push(normalized_node);
return node.id;
});
The problem with code above is that later, the only way to search for data is to peek them by individual data types:
either:
this.store.peekAll('folder') // correctly returns nodes which are of type: 'folders'
or
this.store.peekAll('document') // correctly returns nodes of type 'documents'
The problem is that later code is supposed to treat them as one array of nodes. Is there a way to combine results of two peekAll call ? How can I push to store - and then retrieve polymorphic models ?