feat: Permetti campi solo relations

This commit is contained in:
Maicol Battistini 2022-01-27 16:56:10 +01:00
parent de80449d58
commit eff551c9e8
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A
1 changed files with 15 additions and 3 deletions

View File

@ -373,6 +373,7 @@ export class RecordsPage extends Page {
}
}
// eslint-disable-next-line sonarjs/cognitive-complexity
async setter(model: IModel, data: Collection<File | string>) {
const firstFields = data.only(this.fieldsPrecedence);
const fields = data.except(this.fieldsPrecedence);
@ -385,10 +386,21 @@ export class RecordsPage extends Page {
data.each((value, field) => {
if (typeof field === 'string' && field.includes(':')) {
const [relation, fieldName] = field.split(':');
const relationModel = this.getRelation(model, relation, true);
let [relation, fieldName]: (string | undefined)[] = field.split(':');
if (fieldName && !relation) {
// If the field is a model id, we need to save the relation and not the field itself
relation = fieldName;
fieldName = undefined;
}
const relationModel = relation in relations
? relations[relation]
: this.getRelation(model, relation, true);
if (relationModel) {
relationModel[fieldName] = value;
if (fieldName) {
relationModel[fieldName] = value;
}
relations[relation] = relationModel;
}
} else {