loopbackio / loopbackio/loopback-next
Polymorphic Relation - Wrong Doc
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 5.1k
- Fork
- 1.1k
- Merge trung bình
- 2 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 27
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với tài liệu Polymorphic relation tại https://loopback.io/doc/en/lb4/Polymorphic-relation.html và so sánh ví dụ Delivery trong đó với các trường được issue báo cáo. Cập nhật ví dụ để quan hệ sử dụng deliverableId và deliverableType, sau đó xác minh rằng ví dụ được ghi trong tài liệu không còn yêu cầu trường deliverable không tồn tại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 48/100