-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@loopback/sequelize] BelongsTo relation sets target entity column name on the source entity #9591
Labels
Comments
The insights you shared make sense to me but can you share details on how to reproduce it? |
It seems like the reproduction steps on #9617 apply to this one too. |
KalleV
added a commit
to KalleV/loopback-next
that referenced
this issue
Sep 4, 2023
…tion Resolves: loopbackio#9591 Signed-off-by: KalleV <kvirtaneva@gmail.com>
8 tasks
KalleV
added a commit
to KalleV/loopback-next
that referenced
this issue
Sep 4, 2023
Resolves: loopbackio#9591 Signed-off-by: KalleV <kvirtaneva@gmail.com>
8 tasks
KalleV
added a commit
to KalleV/loopback-next
that referenced
this issue
Sep 4, 2023
Resolves: loopbackio#9591 Signed-off-by: KalleV <kvirtaneva@gmail.com> test(sequelize): replicate duplicate column error with Sequelize belongsTo Relates to: - loopbackio#9617 - sourcefuse/loopback4-sequelize#35
8 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I encountered an issue with a @BelongsTo relation adding column names to a SELECT query that did not exist on the source table when testing the sequelize extension. I traced it to this section:
loopback-next/extensions/sequelize/src/sequelize/sequelize.repository.base.ts
Lines 626 to 634 in f751040
The "keyTo" assignment to the "foreignKey" causes the target entity column to be assigned back to the source entity by Sequelize leading to a broken query: https://github.com/sequelize/sequelize/blob/a9fd5010809366eb50fa9d6fc4bf0612a9d1d751/src/associations/mixin.js#L38. Looks like the fix is to swap the "keyTo" to "keyFrom" because the Sequelize belongsTo "foreignKey" is the source entity column name rather than the target.
References:
https://sequelize.org/api/v6/class/src/model.js~model#static-method-belongsTo
https://loopback.io/doc/en/lb4/BelongsTo-relation.html#relation-metadata
Logs
No response
Additional information
No response
Reproduction
N/A
The text was updated successfully, but these errors were encountered: