dfahlander / dexie-relationships

Dexie relationship plugin
MIT License
89 stars 17 forks source link

When foreign key is null, we get an error #25

Closed tdesvenain closed 6 years ago

tdesvenain commented 6 years ago

Could not lookup foreign key where ... The content of the failing key was: null.

In my opinion the relation property should just be null there.

tdesvenain commented 6 years ago

When I test for non null or undefined before throw, it just works as I expect

          // Populate column on each row
          rows.forEach(function (row) {
            var foreignKey = row[targetIndex];
            var record = lookup[foreignKey];
            if (foreignKey !== null && foreignKey !== undefined && !record) {  // test if not null or undefined
              throw new Error(
                "Could not lookup foreign key where " +
                tableName + "." + foreignIndex + " == " + baseTable + "." + column + ". " +
                "The content of the failing key was: " + (JSON.stringify(foreignKey)) + ".")
            }

would you agree with such a change ?

tdesvenain commented 6 years ago

https://github.com/ignasbernotas/dexie-relationships/blob/master/src/index.js#L123

tdesvenain commented 6 years ago

Hi do you have an opinion about this fix ?

dfahlander commented 6 years ago

Hi! Sorry for getting into this so late. Notification emails for this library went into gmail's Forum tab. I've created a rule to get it right in future.

Yes, I agree totally. If you PR, I'll gladly merge it.