Akita: upsert returns object instead of class instance for newly added entities

Created on 27 Mar 2019  路  5Comments  路  Source: datorama/akita

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I have an EntityStore with stores Conversation class instances. When using upsert an already existing entity is updated correctly and is returned as a Conversation instance. However when a new instance is upserted and fetched with a getAll query it is returned as a regular Object, not a Conversation object. Thus all related Conversation functions are gone.

I am upserting like this: store.upsert(conversation.getId(), conversation)

Expected behavior

upserting a new instance should store the class instance, not a default object

Minimal reproduction of the problem with instructions

For bug reports please provide the STEPS TO REPRODUCE and if possible a MINIMAL DEMO of the problem via
https://stackblitz.com or similar (you can use this template as a starting point: https://stackblitz.com/github/NetanelBasal/akita-issue-seed).

What is the motivation / use case for changing the behavior?

Environment


Angular version: 7.1.4


Browser:
- [X] Chrome (desktop) version 73.0.3683.86
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Most helpful comment

store.upsert(1, { title: 'new title' }, { baseClass: Todo });

All 5 comments

However when a new instance is upserted

Akita can't know that this is a class-based object. When using set() or add() you're responsible for doing it.

So you mean I need to use add() instead of upsert() in my case?

The idea then is to check if the object already exists in the store, if yes, use upsert(), if no use add(). Correct?

I will add a third options parameter that you can pass the base class.

If that would make it work that would be awesome!

store.upsert(1, { title: 'new title' }, { baseClass: Todo });

Was this page helpful?
0 / 5 - 0 ratings