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,
});
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({
railsId: DS.attr('number'),
siteId: DS.attr('number'),
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'),
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'),
hourlyCharge: DS.attr('number', {defaultValue: 0.0}),
doubleEvent: DS.attr('number'),
weekdays: DS.attr('boolean', {defaultValue: null}),
weekends: DS.attr('boolean', {defaultValue: null}),
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})
});