mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-23 23:07:46 +01:00
fix: Imposta valore nel campo relation
This commit is contained in:
parent
1fb739ed75
commit
438ae9622c
@ -64,6 +64,8 @@ export type SectionsT = Record<string, SectionT>;
|
||||
|
||||
const FIELDS: string = 'text-field, text-area, material-select';
|
||||
|
||||
// TODO: Refactor con l'utilizzo di sottocomponenti (es. per le dialog)
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
*/
|
||||
@ -540,11 +542,27 @@ export class RecordsPage extends Page {
|
||||
raw = false
|
||||
): Promise<any> {
|
||||
const column = this.columns[field];
|
||||
const sectionField = collect(this.sections)
|
||||
.pluck(`fields.${field}`)
|
||||
.first() as SelectT | null;
|
||||
let value: unknown;
|
||||
if (field.includes(':')) {
|
||||
const [relation, fieldName] = field.split(':');
|
||||
const relationModel = await this.getRelation(model, relation);
|
||||
value = relationModel?.[fieldName];
|
||||
if (field.includes(':') || sectionField?.relationship) {
|
||||
let relation;
|
||||
let fieldName = '';
|
||||
|
||||
if (field.includes(':')) {
|
||||
[relation, fieldName] = field.split(':');
|
||||
const blankModel = await this.getRelation(model, relation);
|
||||
const relatedModel = await blankModel?.fresh();
|
||||
value = relatedModel?.[fieldName];
|
||||
} else {
|
||||
if (Array.isArray(sectionField?.relationship)) {
|
||||
fieldName = sectionField?.relationship[1] as string;
|
||||
}
|
||||
relation = field;
|
||||
const relatedModel = await this.getRelation(model, relation);
|
||||
value = relatedModel?.getId();
|
||||
}
|
||||
} else {
|
||||
value = model[field];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user