loopbackio / loopbackio/loopback-next
Polymorphic Relation - Wrong Doc
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Describe the bug
Hi there!
Let's suppose a base Delivery model with 3 fields: id, deliverableType, and deliverableId.
If you follow the docs, 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Polymorphic relation documentation at https://loopback.io/doc/en/lb4/Polymorphic-relation.html and compare its Delivery example with the issue's reported fields. Update the example so the relation uses deliverableId and deliverableType, then verify that the documented example no longer requests the nonexistent deliverable field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100