Closed ReneHollander closed 6 years ago
Hey @ReneHollander, this is not working with associations only, you need to use scopes additionally. See here a discussion about it: https://github.com/sequelize/sequelize/issues/311
And here is the documentation of scopes in associations: http://docs.sequelizejs.com/manual/tutorial/associations.html#scopes
If you have issues getting this to work, just come back and I try to help you with this :)
Thanks for getting back! I actually found that issue and with that I gave up and tried using typeorm. But typeorm is also not behaving correctly with composite keys. I will try it again with sequelize. (I also did not see the hint with the scopes...)
Hey @ReneHollander, this is not working with associations only, you need to use scopes additionally. See here a discussion about it: sequelize/sequelize#311
And here is the documentation of scopes in associations: http://docs.sequelizejs.com/manual/tutorial/associations.html#scopes
If you have issues getting this to work, just come back and I try to help you with this :)
@RobinBuschmann, I am facing this same issue in Referencing a Foreign Key from one table to another having Composite Primary Key. According to what you suggested I tried using Scopes, but was still unable to get it working. Can you please share an example of how to link such table's using Scopes? Thanks much in advance.
This is the structure for Table Relation.
I am using compound keys in my model. For example I have a city table which uses the postcode and name as a compound key:
Which results in the following create which looks correct:
I then want to reference this table from my user table:
But as you can see, no foreign key constraints are added to the table:
I am assuming I have to somehow reference the actual attributes in the other table from the user table, but I am not sure how to do it.