summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index c450e2bedc7..1d8e68c3e62 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -2634,13 +2634,21 @@ var BasicModel = AbstractModel.extend({
}
commands[fieldName].push(command);
} else if (_.contains(addedIds, list.res_ids[i])) {
- // this is a new id
+ // this is a new id (maybe existing in DB, but new in JS)
relRecord = _.findWhere(relRecordAdded, {res_id: list.res_ids[i]});
changes = this._generateChanges(relRecord, options);
if ('id' in changes) {
+ // the subrecord already exists in db
delete changes.id;
- commands[fieldName].push(x2ManyCommands.update(relRecord.res_id, changes));
+ if (this.isNew(record.id)) {
+ // if the main record is new, link the subrecord to it
+ commands[fieldName].push(x2ManyCommands.link_to(relRecord.res_id));
+ }
+ if (!_.isEmpty(changes)) {
+ commands[fieldName].push(x2ManyCommands.update(relRecord.res_id, changes));
+ }
} else {
+ // the subrecord is new, so create it
commands[fieldName].push(x2ManyCommands.create(changes));
}
}