diff --git a/tine20/library/ExtJS/src/data/Record.js b/tine20/library/ExtJS/src/data/Record.js index 20286a06de6..0afb57aa783 100644 --- a/tine20/library/ExtJS/src/data/Record.js +++ b/tine20/library/ExtJS/src/data/Record.js @@ -8,7 +8,7 @@ const { extend, isPrimitive, isEmpty } = require("Ext/core/core/Ext"); const Field = require("Ext/data/DataField"); const MixedCollection = require("Ext/util/MixedCollection"); -const { cloneDeep, forEach } = require('lodash'); +const { get, isFunction, isUndefined, forEach } = require('lodash'); /** * @class Record @@ -413,7 +413,24 @@ Record.id(rec); // automatically generate a unique sequential id * @return {Record} */ copy : function(newId) { - return new this.constructor(cloneDeep(this.data), newId || this.id); + const data = this.getData(); + data[this.idProperty] = isUndefined(newId) ? data[this.idProperty] : newId; + const copy = Tine.Tinebase.data.Record.setFromJson(data, this.constructor); + forEach(this.data, (v, k) => { + if (isFunction(get(v, 'copy'))) { + this.data[k] = v.copy(); + } + }); + forEach(this.__metaFields, (m) => { + if (this.hasOwnProperty(m)) { + copy[m] = this[m]; + } + }); + copy.modified = []; + forEach(this.modified, (v, k) => { + copy.modified[k] = isFunction(get(v, 'copy')) ? v.copy() : this.modified[k]; + }); + return copy; }, /**