Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[@loopback/sequelize] Duplicate column names in relation queries

Đang mở
#9,617 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
node.js, typescript
Lĩnh vực
api, backend, database

Hướng nghiên cứu

Bắt đầu với các bài kiểm thử extension của Sequelize và các thay đổi để tái hiện trong commit 3c29d852b46f19f4805d556ae32aee49c79471f1. Kiểm tra thiết lập quan hệ Patient và cách xử lý keyFrom, keyTo và through trước khi truy vấn đến Sequelize. Hoàn thành khi các quan hệ không có mọi thuộc tính được thiết lập rõ ràng không còn tạo ra các cột trùng lặp, với kiểm thử hồi quy trong các bài kiểm thử extension.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug sequelize
Describe the bug

Repository queries with relations that do not explicitly set all the keyTo / keyFrom / through properties will lead to broken SQL queries that contain duplicated title case column names mixed in with the expected camelcase columns.

Example:

SELECT bookid as bookId, reader.id as readerId, ReaderId …

Relates to:
https://github.com/sequelize/sequelize/issues/9328
https://github.com/loopbackio/loopback-next/issues/9591
https://github.com/sourcefuse/loopback4-sequelize/issues/35

Logs

No response

Additional information

Workaround seems to be to go through all the Entity relations and explicitly set all the relation key names but that can be time-consuming and error-prone with a larger project. It seems like it might be possible to mitigate this at the loopback model to Sequelize relation layer.

Reproduction

With these changes, running the tests for the Sequelize extension will replicate the error:
https://github.com/KalleV/loopback-next/commit/3c29d852b46f19f4805d556ae32aee49c79471f1

Turns out it's necessary to define additional "belongsTo" relations in other entities before this happens. The extra relation is added to the "Patient" entity in this case. With this set up, I am seeing the following happen:

  • The default relation properties are set by Loopback (i.e. I can see the "keyFrom" is populated as todoListId) but the "keyTo" is undefined:
    loopback_relation_data
  • This leads to undefined being passed as the foreign key to sequelize:
    undefined_foreign_key
  • And then that causes Sequelize to assign a Title Case property through it's own default relation column logic leading to a duplicate column name in the database query:
    duplicate_column_sqlite_error
Ngôn ngữ chính
TypeScript
Star
5.1k
Fork
1.1k
Merge trung bình
5 ngày 9 giờ
Pull request đã merge (30 ngày)
27

Chuẩn bị môi trường

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.

Issue khác của loopbackio/loopback-next

Tất cả issue của loopbackio/loopback-next

Issue tương tự

Thêm issue về TypeScript

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.