-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
š Fix
Field.Schema
contents not being converted from database repreā¦
ā¦sentation
- Loading branch information
Showing
2 changed files
with
59 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,12 +410,12 @@ SchemaField.setMethod(function _toApp(query, options, value, callback) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.0 | ||
* @version 1.3.16 | ||
* @version 1.4.0 | ||
* | ||
* @param {Mixed} value | ||
* @param {Function} callback | ||
*/ | ||
SchemaField.setMethod(function _toAppFromValue(query, options, value, callback) { | ||
SchemaField.setMethod(async function _toAppFromValue(query, options, value, callback) { | ||
|
||
var that = this, | ||
recursive, | ||
|
@@ -427,7 +427,11 @@ SchemaField.setMethod(function _toAppFromValue(query, options, value, callback) | |
recursive = options.recursive; | ||
|
||
if (recursive == null) { | ||
recursive = 1; | ||
if (this.options?.recursive != null) { | ||
recursive = this.options.recursive; | ||
} else { | ||
recursive = 1; | ||
} | ||
} | ||
|
||
if (recursive && Blast.isBrowser) { | ||
|
@@ -436,59 +440,6 @@ SchemaField.setMethod(function _toAppFromValue(query, options, value, callback) | |
recursive = 0; | ||
} | ||
|
||
// Get associated records if the subschema has associations defined | ||
if (recursive && this.field_schema && !Object.isEmpty(this.field_schema.associations)) { | ||
|
||
name = this.name + 'FieldModel'; | ||
Dummy = alchemy.getModel('Model', false); | ||
|
||
Dummy = new Dummy({ | ||
root_model : this.root_model, | ||
name : name | ||
}); | ||
|
||
item = {}; | ||
|
||
item[name] = value; | ||
|
||
let sub_criteria = Dummy.find(); | ||
|
||
// Disable generating Document instances | ||
// if the original find did the same | ||
sub_criteria.setOption('document', options.document); | ||
sub_criteria.setOption('original_query', query); | ||
sub_criteria.setOption('_root_data', options._root_data); | ||
sub_criteria.setOption('_parent_field', that); | ||
sub_criteria.setOption('_parent_model', that.schema.model_name); | ||
sub_criteria.setOption('recursive', recursive); | ||
|
||
sub_criteria.setOption('associations', this.field_schema.associations); | ||
|
||
// @todo: inherit other original find options? | ||
|
||
Dummy.addAssociatedDataToRecord(sub_criteria, item, function gotAssociatedData(err, result) { | ||
|
||
var key; | ||
|
||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
for (key in result) { | ||
if (key == name) { | ||
continue; | ||
} | ||
|
||
value[key] = result[key]; | ||
} | ||
|
||
callback(null, value); | ||
} | ||
); | ||
|
||
return; | ||
} | ||
|
||
let record; | ||
|
||
if (options.parent_value) { | ||
|
@@ -538,14 +489,60 @@ SchemaField.setMethod(function _toAppFromValue(query, options, value, callback) | |
} | ||
}); | ||
|
||
return Function.parallel(4, tasks, function convertedFields(err, result) { | ||
value = await Function.parallel(4, tasks); | ||
} | ||
|
||
if (err) { | ||
return callback(err); | ||
} | ||
// Get associated records if the subschema has associations defined | ||
if (recursive && this.field_schema && !Object.isEmpty(this.field_schema.associations)) { | ||
|
||
callback(null, that.castEntry(result)); | ||
name = this.name + 'FieldModel'; | ||
Dummy = alchemy.getModel('Model', false); | ||
|
||
Dummy = new Dummy({ | ||
root_model : this.root_model, | ||
name : name | ||
}); | ||
|
||
item = {}; | ||
|
||
item[name] = value; | ||
|
||
let sub_criteria = Dummy.find(); | ||
|
||
// Disable generating Document instances | ||
// if the original find did the same | ||
sub_criteria.setOption('document', options.document); | ||
sub_criteria.setOption('original_query', query); | ||
sub_criteria.setOption('_root_data', options._root_data); | ||
sub_criteria.setOption('_parent_field', that); | ||
sub_criteria.setOption('_parent_model', that.schema.model_name); | ||
sub_criteria.setOption('recursive', recursive); | ||
|
||
sub_criteria.setOption('associations', this.field_schema.associations); | ||
|
||
// @todo: inherit other original find options? | ||
|
||
Dummy.addAssociatedDataToRecord(sub_criteria, item, function gotAssociatedData(err, result) { | ||
|
||
var key; | ||
|
||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
for (key in result) { | ||
if (key == name) { | ||
continue; | ||
} | ||
|
||
value[key] = result[key]; | ||
} | ||
|
||
callback(null, value); | ||
} | ||
); | ||
|
||
return; | ||
} | ||
|
||
callback(null, this.castEntry(value)); | ||
|