KoSik
26 Oct 2012, 5:06 AM
Mapping is not applied to idProperty of the model.
Here is how id field of the model declared:
config: {
idProperty: 'id',
fields: [
{
name: 'id',
mapping: 'taskId',
type: 'int'
}, {
name: 'title',
mapping: 'taskTitle',
type: 'string'
}
]
}
When I try to save non-phantom record (updating) - it sends following request to server:
{"taskTitle":"Test title","id":"169"}
But it should send the following, after applying mapping:
{"taskTitle":"Test title","taskId":"169"}
Problem is inside Writer.js file, where mapping is applied to all properties, except idProperty:
getRecordData: function(record) {
var isPhantom = record.phantom === true,
writeAll = this.getWriteAllFields() || isPhantom,
nameProperty = this.getNameProperty(),
fields = record.getFields(),
data = {},
changes, name, field, key, value;
if (writeAll) {
fields.each(function(field) {
if (field.getPersist()) {
name = field.config[nameProperty] || field.getName();
value = record.get(field.getName());
if (field.getType().type == 'date' && value !== null) {
value = this.writeDate(field, value);
}
data[name] = value;
}
}, this);
} else {
// Only write the changes
changes = record.getChanges();
for (key in changes) {
if (changes.hasOwnProperty(key)) {
field = fields.get(key);
if (field.getPersist()) {
name = field.config[nameProperty] || field.getName();
value = changes[key];
if (field.getType().type == 'date') {
value = this.writeDate(field, value);
}
data[name] = value;
}
}
}
if (!isPhantom) {
// always include the id for non phantoms
data[record.getIdProperty()] = record.getId(); <--- Mapping should be applied to the record.getIdProperty() index
}
}
return data;
}
Of course, it is possible to fix it by defining idProperty: "taskId", but this is not correct, because there is not property called "taskId", it should be "id".
Here is how id field of the model declared:
config: {
idProperty: 'id',
fields: [
{
name: 'id',
mapping: 'taskId',
type: 'int'
}, {
name: 'title',
mapping: 'taskTitle',
type: 'string'
}
]
}
When I try to save non-phantom record (updating) - it sends following request to server:
{"taskTitle":"Test title","id":"169"}
But it should send the following, after applying mapping:
{"taskTitle":"Test title","taskId":"169"}
Problem is inside Writer.js file, where mapping is applied to all properties, except idProperty:
getRecordData: function(record) {
var isPhantom = record.phantom === true,
writeAll = this.getWriteAllFields() || isPhantom,
nameProperty = this.getNameProperty(),
fields = record.getFields(),
data = {},
changes, name, field, key, value;
if (writeAll) {
fields.each(function(field) {
if (field.getPersist()) {
name = field.config[nameProperty] || field.getName();
value = record.get(field.getName());
if (field.getType().type == 'date' && value !== null) {
value = this.writeDate(field, value);
}
data[name] = value;
}
}, this);
} else {
// Only write the changes
changes = record.getChanges();
for (key in changes) {
if (changes.hasOwnProperty(key)) {
field = fields.get(key);
if (field.getPersist()) {
name = field.config[nameProperty] || field.getName();
value = changes[key];
if (field.getType().type == 'date') {
value = this.writeDate(field, value);
}
data[name] = value;
}
}
}
if (!isPhantom) {
// always include the id for non phantoms
data[record.getIdProperty()] = record.getId(); <--- Mapping should be applied to the record.getIdProperty() index
}
}
return data;
}
Of course, it is possible to fix it by defining idProperty: "taskId", but this is not correct, because there is not property called "taskId", it should be "id".