loopbackio / loopbackio/loopback-next

Polymorphic Relation - Wrong Doc

Đang mở
#8,667 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug Docs
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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.