Cannot read property "defineRelationshipType" when trying to save () a model with hasMany Relationship

I ran into a tough error when trying to save an entry with a LocalStorage adapter that has a hasMany relationship (using the Ember CLI). What I am trying to do is save the product in the bag when the user clicks on the Add to Bag button. I am getting this error in the console:

Uncaught TypeError: Cannot read property 'determineRelationshipType' of undefined

Product model:

import DS from 'ember-data';

export default DS.Model.extend({
  ...
  bag: DS.belongsTo('bag')

});

      

Bag model:

import DS from 'ember-data';

export default DS.Model.extend({
  products: DS.hasMany('product', {async: true})
});

      

Here's the action in the controller:

import Ember from "ember";

export default Ember.ArrayController.extend({
  actions: {
    addToBag: function(model) {
      var bag = this.store.createRecord('bag');
      bag.get('products').then(function(products) {
        products.pushObject(model);
        bag.save();
      });
    }
  }
});

      

Anyone have an idea what is going wrong? Or another way to approach this? It looks like a similar issue has been presented here . Any help would be greatly appreciated! Thank you in advance.

+3


source to share


2 answers


I have re-investigated this issue and it seems to have been addressed in a recent update to ember-localstorage-adapter

. In particular, the link to DS.RelationshipChange has been removed .

In my bower.json

I back version ember-data

back in 1.0.0-beta.11

, as well as to determine the version ember-localstorage-adapter

of the latest version 0.5.0

. Here's the relevant information in the file bower.json

:



{
  "name": "****",
  "dependencies": {    
    "ember": "1.8.1",
    "ember-data": "1.0.0-beta.11",
    "ember-localstorage-adapter": "~0.5.0",
  }
}

      

This error doesn't appear anymore!

+2


source


I started a project using emberfire adapter and faced the same problem.

Without getting into it, it looks like the ember data beta10 is not recommended to use the function that hasMany needs to work. (Further reading https://github.com/firebase/emberfire/issues/123 )

Downgrading to ember data 8 beta fixed the issue for me.

This is required until the adapters (emberfire and / or localstorage) are updated.



In my ember-cli project, I did:

rm -rf vendor/ember-data/ bower cache clean ember-data

Edit files vendor/emberfire/bower.json

and vendor/emberfire/.bower.json

to say "ember-data": "1.0.0-beta.8"

.

bower install

+2


source







All Articles