1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-06-05 22:09:38 +02:00

feat: Permetti campi solo relations

This commit is contained in:
Maicol Battistini
2022-01-27 16:56:10 +01:00
parent de80449d58
commit eff551c9e8

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>) { async setter(model: IModel, data: Collection<File | string>) {
const firstFields = data.only(this.fieldsPrecedence); const firstFields = data.only(this.fieldsPrecedence);
const fields = data.except(this.fieldsPrecedence); const fields = data.except(this.fieldsPrecedence);
@@ -385,10 +386,21 @@ export class RecordsPage extends Page {
data.each((value, field) => { data.each((value, field) => {
if (typeof field === 'string' && field.includes(':')) { if (typeof field === 'string' && field.includes(':')) {
const [relation, fieldName] = field.split(':'); let [relation, fieldName]: (string | undefined)[] = field.split(':');
const relationModel = this.getRelation(model, relation, true); 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) { if (relationModel) {
if (fieldName) {
relationModel[fieldName] = value; relationModel[fieldName] = value;
}
relations[relation] = relationModel; relations[relation] = relationModel;
} }
} else { } else {