Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check field associated entity and add missing fields #58

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
18 changes: 17 additions & 1 deletion src/services/MetaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ export class MetaService {
const exists = this.fields.find((f: any) => f.name === field.name);
if (!exists) {
this.fields.push(field);
} else if (field.associatedEntity && field.associatedEntity.fields) {
for (const assocEntityField of field.associatedEntity.fields) {
const assocEntityFieldExists = exists.associatedEntity.fields.find((f: { name: string }) => f.name === assocEntityField.name);
if (!assocEntityFieldExists) {
exists.associatedEntity.fields.push(assocEntityField);
}
}
}
if (typeof field !== 'string') {
this.memory[field.name] = field;
Expand Down Expand Up @@ -254,7 +261,7 @@ export class MetaService {
for (const field of fields) {
const cleaned: string = this._clean(field);
const meta: any = this.memory[cleaned];
if (!meta) {
if (!meta || meta.associatedEntity && meta.associatedEntity.fields.length < this.subFieldLength(field)) {
bvkimball marked this conversation as resolved.
Show resolved Hide resolved
result.push(cleaned);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something i might have missed earlier is that we are pushing cleaned that seems wrong because all the default fields would have to be included, Maybe that is true for INLINE_EMBEDDED.

was think something more like

  private missing(fields): string[] {
    if (!this.memory) {
      return fields;
    }
    if (fields && fields[0] === '*' && this.allFieldsLoaded) {
      return [];
    }
    const result: string[] = [];
    for (const field of fields) {
      const cleaned: string = this._clean(field);
      const meta: any = this.memory[cleaned];
      if (!meta) {
        // We can't push `cleaned` field because that wouldn't request subField
        result.push(field);
      } else if (meta.associatedEntity) {
        const aefs = meta.associatedEntity.fields.map(aef => aef.name);
        // filter out any existing associatedEntity fields
        // but this probably needs to be recursive or the subfields need to be cleaned
        const missingSubFields = this.getSubFields(field).filter(sub => !aefs.includes(sub));
        // construct field with missing sub fields
        result.push(`${cleaned}(${missingSubFields.join()})`);
      }
    }
    return result;
  }

}
}
Expand All @@ -268,6 +275,15 @@ export class MetaService {
.split('(')[0];
}

subFieldLength(field: string): number {
if (field.includes('(')) {
return field
.split('(')[1]
.split(',').length;
}
return 0;
}

/**
* Get specific meta data properties
*/
Expand Down