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

Unable to load relations due to self being declared twice #46

Open
JeffreyDevloo opened this issue Sep 22, 2017 · 0 comments
Open

Unable to load relations due to self being declared twice #46

JeffreyDevloo opened this issue Sep 22, 2017 · 0 comments

Comments

@JeffreyDevloo
Copy link

JeffreyDevloo commented Sep 22, 2017

Problem descriptions

Relations cannot be fetched due to a bug.

core.es5.js:1020 ERROR TypeError: Cannot read property 'makeHasManyLocalKeys' of undefined
    at js-data-localstorage.js:1221
    at Array.forEach (<anonymous>)
    at js-data-localstorage.js:1220
    at LocalStorageAdapter.loadHasManyLocalKeys (js-data-localstorage.js:1245)
    at js-data-localstorage.js:1109
    at Object._forRelation (js-data.js:250)
    at js-data.js:894
    at Array.forEach (<anonymous>)
    at Object.forEachRelation (js-data.js:893)
    at js-data-localstorage.js:1100

The line of code causing the issue:

loadHasManyLocalKeys: function loadHasManyLocalKeys(mapper, def, records, __opts) {
      var self = this;
      var record = void 0;
      var relatedMapper = def.getRelation();

      if (jsData.utils.isObject(records) && !jsData.utils.isArray(records)) {
        record = records;
      }

      if (record) {
        return self.findAll(relatedMapper, {
          where: babelHelpers.defineProperty({}, relatedMapper.idAttribute, {
            'in': self.makeHasManyLocalKeys(mapper, def, record)
          })
        }, __opts).then(function (relatedItems) {
          def.setLocalField(record, relatedItems);
        });
      } else {
        var _ret2 = function () {
          var localKeys = [];
          records.forEach(function (record) {
            localKeys = localKeys.concat(self.self.makeHasManyLocalKeys(mapper, def, record));
          });
          return {
            v: self.findAll(relatedMapper, {
              where: babelHelpers.defineProperty({}, relatedMapper.idAttribute, {
                'in': unique(localKeys).filter(function (x) {
                  return x;
                })
              })
            }, __opts).then(function (relatedItems) {
              records.forEach(function (item) {
                var attached = [];
                var itemKeys = jsData.utils.get(item, def.localKeys) || [];
                itemKeys = jsData.utils.isArray(itemKeys) ? itemKeys : Object.keys(itemKeys);
                relatedItems.forEach(function (relatedItem) {
                  if (itemKeys && itemKeys.indexOf(relatedItem[relatedMapper.idAttribute]) !== -1) {
                    attached.push(relatedItem);
                  }
                });
                def.setLocalField(item, attached);
              });
              return relatedItems;
            })
          };
        }();

        if ((typeof _ret2 === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret2)) === "object") return _ret2.v;
      }
    },

localKeys = localKeys.concat(self.self.makeHasManyLocalKeys(mapper, def, record));
Self is declared twice (like 1221 in the npm version of the 3.0.1beta2). The current this scope has no variable called self.
Removing one of the duplicate selfs has resolved my issue,

Thanks!

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

1 participant