Skip to content

Commit 1ee21ca

Browse files
committed
Improve JSON property management
1 parent 1bf57b5 commit 1ee21ca

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/component.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,9 @@ function addProperties(model, Class, classId) {
886886
case propertyType === 'date':
887887
propertyValue = new Date(component[propertyName]);
888888
break;
889+
case propertyType === 'json':
890+
propertyValue = JSON.parse(JSON.stringify(component[propertyName]));
891+
break;
889892
case propertyType === 'array':
890893
propertyValue = new _Array({
891894
'id': this.id(),
@@ -1143,6 +1146,9 @@ function addStructure(path, name, model, id) {
11431146
case propertyType === 'date':
11441147
propertyValue = new Date(getStructureValue(model, id, fullPath));
11451148
break;
1149+
case propertyType === 'json':
1150+
propertyValue = JSON.parse(JSON.stringify(getStructureValue(model, id, fullPath)));
1151+
break;
11461152
case $metamodel.isStructure(propertyName, model):
11471153
propertyValue = addStructure(parentPath, propertyName, model, id);
11481154
break;
@@ -1204,7 +1210,7 @@ function addStructure(path, name, model, id) {
12041210
}
12051211
}
12061212
};
1207-
1213+
12081214
/* jshint -W054 */
12091215
sructure[propertyName] = new Function('__body', 'return function ' + propertyName + ' (value) { return __body.call(this,value) };')(body);
12101216
/* jshint +W054 */

src/db.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,16 @@ DatabaseCollection.prototype.update = function (query, update, options) {
701701
}
702702

703703
for (attributeName in update) {
704-
if (typeof docs[i][attributeName] !== 'undefined') {
704+
if (typeof docs[i][attributeName.split('.')[0]] !== 'undefined') {
705705
if (this.name !== '_Schema' && this.name !== '_Model' && this.name !== '_GeneratedModel') {
706706
// check type
707707
type = '';
708708
if (attributeName.indexOf('_') !== 0) {
709-
type = schema[attributeName].type;
709+
if (attributeName.indexOf('.') !== -1) {
710+
type = $metamodel.getModelPathType(this.name, attributeName);
711+
} else {
712+
type = schema[attributeName].type;
713+
}
710714
} else {
711715
if ($metamodel.getMetaDef()[attributeName]) {
712716
type = $metamodel.getMetaDef()[attributeName].type;
@@ -727,13 +731,21 @@ DatabaseCollection.prototype.update = function (query, update, options) {
727731
'value': update[attributeName]
728732
});
729733
}
730-
$workflow.state({
731-
'component': docs[i]._id,
732-
'state': attributeName,
733-
'data': [update[attributeName]]
734-
});
734+
if (type === 'array') {
735+
$workflow.state({
736+
'component': docs[i]._id,
737+
'state': attributeName,
738+
'data': [update[attributeName], 'reset']
739+
});
740+
} else {
741+
$workflow.state({
742+
'component': docs[i]._id,
743+
'state': attributeName,
744+
'data': [update[attributeName]]
745+
});
746+
}
735747
} else {
736-
$log.invalidPropertyTypeOnDbUpdate(this.name, docs[i]._id, attributeName, update[attributeName], schema[attributeName].type);
748+
$log.invalidPropertyTypeOnDbUpdate(this.name, docs[i]._id, attributeName, update[attributeName], type);
737749
}
738750
} else {
739751
$log.unknownPropertyOnDbUpdate(this.name, attributeName, docs[i]._id);

0 commit comments

Comments
 (0)