loopbackio / loopbackio/loopback-next
Polymorphic Relation - Wrong Doc
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 5.1k
- Forks
- 1.1k
- Ø Merge
- 2 T. 21 Std.
- Gemergte PRs (30 T.)
- 27
Beschreibung
### Describe the bug
Hi there!
Let's suppose a base Delivery model with 3 fields: id, deliverableType, and deliverableId.
If you follow the [docs](https://loopback.io/doc/en/lb4/Polymorphic-relation.html), you'll get this error when requesting some deliverable relations:
> Request GET /deliveries?filter=whatever failed with status code 500. Error: ER_BAD_FIELD_ERROR: Unknown column 'deliverable' in 'field list'
This is caused by this part of code, as you're asking it to search on the corresponding datasource for the field "deliverable" which doesn't exist:
```
class Delivery extends Entity {
@hasOne(() => Deliverable, {polymorphic: true})
deliverable: Deliverable;
deliverableType: string;
}
```
Instead, it should be like this (search deliverableId on deliverableType's model):
```
class Delivery extends Entity {
@hasOne(() => Deliverable, {polymorphic: true})
deliverableId: string;
deliverableType: string;
id: string;
}
```
With that change, polymorphic relation is working as expected (assuming repositories are correctly configured)
### Logs
_No response_
### Additional information
_No response_
### Reproduction
Not needed
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Dokumentation zu Polymorphic relation unter https://loopback.io/doc/en/lb4/Polymorphic-relation.html und vergleiche deren Delivery-Beispiel mit den im Issue gemeldeten Feldern. Aktualisiere das Beispiel so, dass die Relation deliverableId und deliverableType verwendet, und überprüfe anschließend, dass das dokumentierte Beispiel nicht mehr das nicht vorhandene Feld deliverable anfordert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 48/100