Skip to content

Commit

Permalink
data.Model: hasNestedFields class field #6255
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Jan 18, 2025
1 parent a8b9b97 commit 165d364
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/data/Model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ class Model extends Base {

/**
* @member {Map} fieldsMap=new Map()
* @protected
*/
fieldsMap = new Map()
/**
* @member {Boolean} hasNestedFields=false
* @protected
*/
hasNestedFields = false

/**
* @param {Object} config
Expand Down Expand Up @@ -86,15 +92,21 @@ class Model extends Base {
* @param {Boolean} isRoot=true
*/
updateFieldsMap(fields, isRoot=true) {
let {fieldsMap} = this;
let me = this,
{fieldsMap} = me;

isRoot && fieldsMap.clear();

me.hasNestedFields = false;

fields.forEach(field => {
fieldsMap.set(field.name, field);

// Assuming that nested fields contain the full path as the name, we do not need a prefix.
field.fields && this.updateFieldsMap(field.fields, false)
if (field.fields) {
me.hasNestedFields = true;
me.updateFieldsMap(field.fields, false)
}
})
}
}
Expand Down

0 comments on commit 165d364

Please sign in to comment.