Ember Fixture adapter does not set record ID

Ok, so I'm trying to copy an existing model as an instance of a new model (so that all attributes are the same except for the identifier. In my template, I have an action copythat passes the model to scope in this place in the list for the controller so that it can be copied. My controller code is below. It seems I can create a new record, but its identifier is set to "fixture-0", "fixture-1", etc., and a call .save()on it (see below) leads to an error.

Uncaught TypeError: Cannot call method 'serialize' of undefined 

Since I am currently arranging models for development, I use the adapter adapter, as it seems to have something to do with this problem.

Controller Code:

REApp.ApplicationController = Ember.ArrayController.extend({
  actions: {
    copy: function(current_model){
      var self = this;
      console.log(current_model);

      var new_record = this.store.createRecord('cycle', {
        railsId: null,
        accountId: current_model._data.accountId,
        //lots more attributes here
      });

      new_record.save();
      console.log(new_record);
    }
  }
});

console.log , new_record:

a {id: "fixture-0", store: a, container: t, currentState: Object, _changesToSync: Object…}

. .save() , id, . .save() (, , ), ember , , .

Ember ( 1.3.0), , .

: . , , varOfModelObject.save(); this.content.save(); , def , Fixture.

REApp.Cycle = DS.Model.extend({
  //id: DS.attr('number'), not needed with fixtures
  railsId: DS.attr('number'),
  siteId: DS.attr('number'), //all numbers here are ints unless noted
  clientId: DS.attr('number'),
  accountId: DS.attr('number'),
  startAt: DS.attr('datetime'),
  endAt: DS.attr('datetime'),
  chargePerEvent: DS.attr('decimal', {defaultValue: 0.0}),
  createdAt: DS.attr('datetime'),
  updatedAt: DS.attr('datetime'),
  scheduleYaml: DS.attr('string'),
  allDay: DS.attr('boolean'),
  repeat: DS.attr('boolean'),
  exceptionDates: DS.attr('string'),
  additionalDates: DS.attr('string'),
  charge: DS.attr('number'), //decimal in rails
  chargePeriod: DS.attr('string'),
  oldRegularEventId: DS.attr('number'),
  scheduleHuman: DS.attr('string'),
  bagLimit: DS.attr('number'),
  untilDate: DS.attr('number'),
  sendToWebfleet: DS.attr('boolean', {defaultValue: false}),
  contractId: DS.attr('number'),
  hourlyRate: DS.attr('number'), //decimal in rails
  hourlyCharge: DS.attr('number', {defaultValue: 0.0}), //decimal in rails
  doubleEvent: DS.attr('number'),
  //these are used for the simple view 
  weekdays: DS.attr('boolean', {defaultValue: null}),
  weekends: DS.attr('boolean', {defaultValue: null}),
  //data below this needed for associations
  clientName: DS.attr('string'),
  commentBody: DS.attr('string'),
  siteAddress: DS.attr('string'),
  carer1Id: DS.attr('number', {defaultValue: null}),
  carer1Name: DS.attr('string'),
  carer2Id: DS.attr('number', {defaultValue: null}),
  carer2Name: DS.attr('string'),
  users: DS.hasMany('user', {async: true}),
  items: DS.hasMany('item', {async: true})
});
+3
2

, , fixture- . , - , Ember Data, , , dev.

0

, , , , , createrecord :

REApp.ApplicationAdapter = DS.FixtureAdapter.extend({
    mockJSON: function(store, type, record) {
      try {
        record.id = Math.floor((Math.random() * 100) + 1);
        return this._super(store, type, record);
      }
      catch(err) {

      }
    },
  }
);
0

All Articles