Open TobiasWehrum opened 5 years ago
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
We're resolving these sort of issues in https://github.com/sequelize/sequelize/pull/14280 by introducing the new inverse
option. Instead of writing
Address.belongsTo(User, { targetKey: "id" });
User.hasOne(Address, { sourceKey: "id" });
you'll be able to write
Address.belongsTo(User, { targetKey: "id", inverse: { type: 'one' } });
and be guaranteed that the options for both sides of the associations are correct
When executing the "Example of a minimal TypeScript project" from http://docs.sequelizejs.com/manual/typescript.html, running
sequelize.sync()
fails with the following error:As you can see, the address table first creates a
userId
key and then yet anotherUserId
key (which it then tries to use as a foreign key).I believe this is in line which what is reported in https://github.com/sequelize/sequelize/issues/3035 and https://github.com/sequelize/sequelize/issues/9328 and I fixed it by replacing
with