mirror of
https://github.com/appy-one/acebase.git
synced 2026-05-25 06:02:14 -06:00
[GH-ISSUE #43] Generating unique keys for child objects #34
Labels
No labels
IndexedDB
browser
bug
dependencies
documentation
duplicate
enhancement
feature request
indexes
indexes
invalid
pull-request
query
question
transaction logging
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/acebase#34
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Devwulf on GitHub (Oct 5, 2021).
Original GitHub issue: https://github.com/appy-one/acebase/issues/43
Hello! If I have this schema:
which are mapped to these models:
Is there a way to auto-generate all the child keys simply by pushing a filled in top-most node into the database, like so?
Currently, the only way I could see to do this is to have this monstrosity of a code just to give the child nodes their own auto-generated keys:
Is there a better way of achieving this? Thanks!
Edit: Seems I was too tired last night to realized this is also possible:
But the problem is still there. This solution really doesn't scale well, once nodes get deeper further down. It would be great if there's a way to automatically generate unique keys for child nodes in object collections, preferably a feature in this library by default.
@appy-one commented on GitHub (Oct 8, 2021):
The best way to do this is using
ID.generate()instead of"*":Or, using backward compatible js:
@Devwulf commented on GitHub (Oct 8, 2021):
I have tried this, but it doesn't seem to work either with LocalStorage or IndexedDB. Only the user node is created, but everything else is missing. Is this not supported for the browser?
@appy-one commented on GitHub (Oct 8, 2021):
This should work just fine in the browser
@Devwulf commented on GitHub (Oct 8, 2021):
I have created a test project implementing this, and it works as expected. However, it does not seem to work when I start binding the classes with custom creators and serializers. I'll try to recreate my main project into a minimal working test project to see if that really is the case.
@Devwulf commented on GitHub (Oct 8, 2021):
I have created a minimal working example that could be found here: test-acebase
That project uses the React Typescript template and only the
App.tsxfile has been edited. The same project can be created using these commands:npx create-react-app test-acebase --template typescriptcd ./test-acebasenpm installApp.tsxfrom the project above to the new project'sApp.tsxThis test project exhibits the problem I'm experiencing with my main project: only the
usersnode is created in the IndexedDB. Perhaps I'm doing something wrong with the binding?@appy-one commented on GitHub (Oct 9, 2021):
Thanks, I'll take a look!
@appy-one commented on GitHub (Oct 9, 2021):
The problem is in your
serializermethods, you are only returning the object's name properties.In your
Usertype mapping, change this:To this:
Do the same for your
Petmapping withawards, and everything should work as expected.@Devwulf commented on GitHub (Oct 10, 2021):
I have confirmed that it works as expected now. Thanks!
I have always thought that serializing child nodes using the serializer will create redundant copies of the child nodes in the IndexedDB key-values, so I never thought to do this. It would be greatly appreciated if both
ID.generate()and serializing child nodes in parent nodes are documented as well!@appy-one commented on GitHub (Oct 11, 2021):
I'll take a look at the docs to see what I can improve 👍🏼