-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Relationships from within arrays? #40
Comments
Been browsing around a bit; this may be similar to #37. |
You can have a fully relational model in IndexedDB as has the most important parts for this: ACID transactions across tables and indices. Dexie-relationships solves only a subset of the use cases and relational models but its really just some syntactic sugar and no foreign key enforcements or full relational support. I find myself using plain dexie queries many times when modelling relational models though. In this case, I would probably just use bulkGet() to resolve them: async function getShoppingBag(shoppingBagId) {
const bag = await db.shoppingBags.get(shoppingBagId);
const itemIds = bag.bagContents.map(bc => bc.itemId);
const referredItems = await db.items.bulkGet(itemIds);
return {
...bag,
bagContents: bag.bagContents.map((bc, idx) => ({
...bc,
item: referredItems[idx]
}))
};
} |
Ah, interesting, seems to work great. Hadn't used get()/bulkGet() before. Until now I have done pretty much everything with .where's, and would have written this like:
Differences are:
and
Both versions return the same results. So, the answer to the original question is, no, not with dexie-relationships. |
|
I have a lot of Dexie tables that have an array with foreign keys. For example, a shopping bag with items:
This was all fine when I my application was always online and my relational backend did all the joining, but now that I'm moving to an offline mode, suddenly all the relational goodness has to be baked in into the IndexedDB key store. But I'm rambling.. so ideally I would make those itemId's point to my item table.
Is this anywhere within the realm of possibilities? Also, it makes me wonder at which point the key store becomes a relational database again ;-).
The text was updated successfully, but these errors were encountered: