Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when including related table that does not have rows corresponding to the foreign key #28

Open
GGAlanSmithee opened this issue Dec 26, 2017 · 3 comments

Comments

@GGAlanSmithee
Copy link

Given the schema

db.version(1).stores({
    bands: '++id, name',
    albums: '++id, bandId -> bands.id, name'
})

If I add a band, but no corresponding album:

await db.bands.put({
    name: "My Band"
})

and then query the DB for bands, including albums by relation;

const bands = await db.bands.with({albums: 'albums'})

I´d expect to get one band with an empty array of albums, but instead I get the error

Promise.js:836 Unhandled rejection: Error: Could not lookup foreign key where albums.bandId == band.albums. The content of the failing key was: 1.

Is this the expected behaviour? Seems a bit odd that you cannot have 0 entities in a one to many relation.

@ccgman123
Copy link

I have been having the same issue.

line 194 of dexie-relationships/dist/index.js is

var record = lookup[foreignKey]

I switched it to the following and it fixed the issue.

var record = lookup[foreignKey] || [];

However i am not sure if this is the proper way of fixing the issue.

@KeithScheiwiller
Copy link

@dfahlander Any input on this? Or your branch for #12? Would either be safe enough to use?

@mickyginger
Copy link
Contributor

Any update on this? I can make a PR for this if helpful

mickyginger added a commit to mickyginger/dexie-relationships that referenced this issue Oct 2, 2019
@mickyginger mickyginger mentioned this issue Oct 2, 2019
dfahlander pushed a commit that referenced this issue Oct 3, 2019
* Fix for issue #28

* Attempting to use as npm package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants