Update documentation for Junction Table UI-Integration and document propagation patterns; include new features and best practices for sync status management
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
# Many-to-Many Junction-Tabelle mit additionalColumns - Testergebnisse
|
||||
|
||||
**Version:** 2.0
|
||||
**Datum:** 11. März 2026
|
||||
**Status:** ✅ VOLLSTÄNDIG ERFOLGREICH mit UI-Integration
|
||||
|
||||
## ✅ VOLLSTÄNDIG ERFOLGREICH!
|
||||
|
||||
**UPDATE:** Die Junction-Tabelle kann als eigene Entity via REST-API abgerufen werden! Seit EspoCRM 6.0.0 werden Junction-Tabellen automatisch als Entities verfügbar gemacht.
|
||||
**UPDATE (März 2026):** Die Junction-Tabelle kann als eigene Entity via REST-API abgerufen werden! Seit EspoCRM 6.0.0 werden Junction-Tabellen automatisch als Entities verfügbar gemacht.
|
||||
|
||||
**NEU:** UI-Anzeige von Junction-Spalten via columnAttributeMap + notStorable Pattern!
|
||||
|
||||
## Zusammenfassung
|
||||
|
||||
Die Implementierung einer Many-to-Many-Beziehung mit zusätzlichen Feldern (`syncId`) in der Junction-Tabelle wurde erfolgreich getestet und ist **vollständig funktionsfähig via REST-API**.
|
||||
Die Implementierung einer Many-to-Many-Beziehung mit zusätzlichen Feldern in der Junction-Tabelle wurde erfolgreich getestet und ist:
|
||||
- **vollständig funktionsfähig via REST-API**
|
||||
- **im UI anzeigbar via columnAttributeMap Pattern**
|
||||
- **automatisch aktualisierbar via Hooks**
|
||||
|
||||
## ✅ Was funktioniert
|
||||
|
||||
@@ -282,6 +291,195 @@ response = requests.put(
|
||||
- ✅ Vollständige CRUD via `/api/v1/CAICollectionCDokumente`
|
||||
- ❌ NICHT in CDokumente detail view als relationship panel anzeigen
|
||||
|
||||
## ✅ LÖSUNG: UI-Anzeige via columnAttributeMap + notStorable
|
||||
|
||||
**UPDATE (März 2026):** Es gibt eine Working-Solution für UI-Anzeige von Junction-Spalten!
|
||||
|
||||
**Pattern:** columnAttributeMap + notStorable Felder
|
||||
|
||||
### Konzept
|
||||
|
||||
1. **notStorable Felder** im Parent: Placeholder für Junction-Spalten
|
||||
2. **columnAttributeMap** in Links: Bidirektionales Mapping
|
||||
3. **Custom List Layouts**: Zeigt notStorable Felder an
|
||||
4. EspoCRM synchronisiert automatisch zwischen Junction-Table und notStorable Feldern
|
||||
|
||||
### Implementierung: CAdvowareAkten ↔ CDokumente
|
||||
|
||||
**CAdvowareAkten.json:**
|
||||
```json
|
||||
{
|
||||
"fields": {
|
||||
"dokumenteHnr": {
|
||||
"type": "int",
|
||||
"notStorable": true,
|
||||
"utility": true
|
||||
},
|
||||
"dokumenteSyncstatus": {
|
||||
"type": "enum",
|
||||
"options": ["new", "unclean", "synced", "failed"],
|
||||
"notStorable": true,
|
||||
"utility": true
|
||||
},
|
||||
"dokumenteLastSync": {
|
||||
"type": "datetime",
|
||||
"notStorable": true,
|
||||
"utility": true
|
||||
},
|
||||
"dokumentes": {
|
||||
"type": "linkMultiple",
|
||||
"columns": {
|
||||
"hnr": "advowareAktenHnr",
|
||||
"syncstatus": "advowareAktenSyncstatus",
|
||||
"lastSync": "advowareAktenLastSync"
|
||||
},
|
||||
"view": "views/fields/link-multiple-with-columns"
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"dokumentes": {
|
||||
"type": "hasMany",
|
||||
"entity": "CDokumente",
|
||||
"foreign": "advowareAktens",
|
||||
"relationName": "cAdvowareAktenDokumente",
|
||||
"additionalColumns": {
|
||||
"hnr": {"type": "int"},
|
||||
"syncstatus": {"type": "varchar", "len": 20},
|
||||
"lastSync": {"type": "datetime"}
|
||||
},
|
||||
"columnAttributeMap": {
|
||||
"hnr": "dokumenteHnr",
|
||||
"syncstatus": "dokumenteSyncstatus",
|
||||
"lastSync": "dokumenteLastSync"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**CDokumente.json (Foreign Side):**
|
||||
```json
|
||||
{
|
||||
"fields": {
|
||||
"advowareAktenHnr": {
|
||||
"type": "int",
|
||||
"notStorable": true,
|
||||
"utility": true,
|
||||
"layoutAvailabilityList": ["listForAdvowareAkten"]
|
||||
},
|
||||
"advowareAktenSyncstatus": {
|
||||
"type": "varchar",
|
||||
"notStorable": true,
|
||||
"utility": true,
|
||||
"layoutAvailabilityList": ["listForAdvowareAkten"]
|
||||
},
|
||||
"advowareAktenLastSync": {
|
||||
"type": "datetime",
|
||||
"notStorable": true,
|
||||
"utility": true,
|
||||
"layoutAvailabilityList": ["listForAdvowareAkten"]
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"advowareAktens": {
|
||||
"type": "hasMany",
|
||||
"entity": "CAdvowareAkten",
|
||||
"foreign": "dokumentes",
|
||||
"relationName": "cAdvowareAktenDokumente",
|
||||
"columnAttributeMap": {
|
||||
"hnr": "advowareAktenHnr",
|
||||
"syncstatus": "advowareAktenSyncstatus",
|
||||
"lastSync": "advowareAktenLastSync"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Custom List Layout (layouts/CDokumente/listForAdvowareAkten.json):**
|
||||
```json
|
||||
[
|
||||
{"name": "name", "width": 25},
|
||||
{"name": "advowareAktenHnr", "width": 10},
|
||||
{"name": "advowareAktenSyncstatus", "width": 12},
|
||||
{"name": "advowareAktenLastSync", "width": 15},
|
||||
{"name": "description", "width": 20}
|
||||
]
|
||||
```
|
||||
|
||||
**Bottom Panel (layouts/CAdvowareAkten/bottomPanelsDetail.json):**
|
||||
```json
|
||||
[
|
||||
{
|
||||
"name": "dokumentes",
|
||||
"label": "Dokumente",
|
||||
"view": "views/record/panels/relationship",
|
||||
"layout": "listForAdvowareAkten",
|
||||
"index": 1
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### Wie es funktioniert
|
||||
|
||||
1. **Lesen:** EspoCRM lädt Junction-Spalten via RDB und mapped sie zu notStorable Feldern
|
||||
2. **Anzeigen:** Custom List Layout zeigt notStorable Felder an
|
||||
3. **Schreiben:** Updates via Hooks mit `updateColumns()`
|
||||
4. **Bidirektional:** columnAttributeMap muss auf beiden Seiten existieren
|
||||
|
||||
### Beispiel: Hook für Auto-Update
|
||||
|
||||
```php
|
||||
<?php
|
||||
namespace Espo\Custom\Hooks\CAdvowareAkten;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\Hook\Hook\AfterRelate;
|
||||
|
||||
class DokumenteSyncStatus implements AfterRelate
|
||||
{
|
||||
public function __construct(
|
||||
private \Espo\ORM\EntityManager $entityManager
|
||||
) {}
|
||||
|
||||
public function afterRelate(
|
||||
Entity $entity,
|
||||
string $relationName,
|
||||
Entity $foreignEntity,
|
||||
array $columnData,
|
||||
\Espo\ORM\Repository\Option\RelateOptions $options
|
||||
): void {
|
||||
if ($relationName !== 'dokumentes') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Setze Junction-Spalten via updateColumns()
|
||||
$repository = $this->entityManager->getRDBRepository('CAdvowareAkten');
|
||||
$repository->getRelation($entity, 'dokumentes')->updateColumns(
|
||||
$foreignEntity,
|
||||
[
|
||||
'syncstatus' => 'new',
|
||||
'lastSync' => null
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Vorteile dieser Lösung
|
||||
|
||||
✅ **UI-Anzeige**: Junction-Spalten sichtbar in Relationship-Panels
|
||||
✅ **Kein 405 Fehler**: Read-only Darstellung vermeidet Inline-Edit-Probleme
|
||||
✅ **API-Kompatibel**: Funktioniert parallel zur Junction-Entity-API
|
||||
✅ **Bidirektional**: Funktioniert von beiden Seiten der Beziehung
|
||||
✅ **Hook-Integration**: Updates via Hooks möglich
|
||||
|
||||
### Einschränkungen
|
||||
|
||||
⚠️ **notStorable = Read-only in UI**: Keine direkte Bearbeitung im Panel
|
||||
⚠️ **Updates via Hooks**: Änderungen müssen über Hooks oder API erfolgen
|
||||
⚠️ **layoutAvailabilityList**: Foreign-Side-Felder nur in Custom Layouts sichtbar
|
||||
|
||||
## 🎯 Fazit
|
||||
|
||||
Die **Junction-Tabelle mit `additionalColumns` ist vollständig via REST-API nutzbar**!
|
||||
|
||||
Reference in New Issue
Block a user