Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emberjs Cannot clone an Ember.Object that does not implement Ember.Copyable

I am using ember 1.3.1 and ember-data 1.0.0-beta.5. On creating new mode I get following error

Assertion failed: Cannot clone an Ember.Object that does not implement Ember.Copyable

Following is my model code

App.myModel = DS.Model.extend({ name : DS.attr('string'), age : DS.attr('string') });

In my create route model function

return Em.Object.create({});

and finally on save I do following

this.store.createRecord('property', this.get('model'));

Although despite the error, my backend service is called successfully and new model is saved.

Please guide.

Thanks

like image 482
amique Avatar asked Jan 24 '14 23:01

amique


2 Answers

I had the same issue which I fixed by doing the following:
In the model function of the route replace

return Em.Object.create({});

with

return this.store.createRecord('myModel');

and on save replace

this.store.createRecord('myModel', this.get('model'));

with

this.get('model').save();
like image 61
Mario Avatar answered Nov 08 '22 08:11

Mario


For the sake of completeness, in the scenario described by @acidleaf this is the solution offered by Yehuda Katz from the ember core team in this video:

Off the Menu: Building a Client-Side With Ember and Rails - Yehuda Katz @ Rails Israel 2013

In the route from which you're returning a list of resources to display (i.e the plural version of the resource StoriesRoute, PostsRoute, etc..), you'll returned a filtered list containing those which are not new:

model: function() {
  this.store.find('myModel');
  return this.store.filter('myModel',function(myModel){
    return !myModel.get('isNew');
  });
}
like image 6
fmendez Avatar answered Nov 08 '22 07:11

fmendez