-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
hasOne 'as' option produces wrong foreign key #10972
Copy link
Copy link
Closed
Labels
docsFor issues and PRs. Things related to documentation, such as changes in the manuals / API reference.For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.
Description
What are you doing?
i'm adding hasOne relationship with {as: ''} option, which leads to foreignKey in target table to be derived from alias name. Though same example is in docs, that is not what i'm expecting
models.User.hasOne(models.Device, {as: 'Calculator'})which leads to query SELECT .. LEFT OUTEER JOIN Devices As Calculator ON User.id = Calculator.CalculatorId instead of Calculator.userId
To Reproduce
Steps to reproduce the behavior:
- Define models X, Y
- Set association 'hasOne' with alias: X.hasOne(Y, {as: 'Z'})
- See error in query, Z.ZId instead of Z.XId
What do you expect to happen?
I want foreign key on target table to be left untouched and derived from source table
What is actually happening?
foreign key is derived from alias instead of source table name
Environment
Dialect:
- mysql
- postgres
- [*] sqlite
- mssql
- any
Sequelize version: 5.7.3
Node Version: 10.x
OS: windows 10
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
docsFor issues and PRs. Things related to documentation, such as changes in the manuals / API reference.For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.