Closed Curtismn87 closed 9 years ago
What do you mean when you say "will only accept"? What error do you get?
There is no error when making the table but all three foreign keys will not be present. I get an error when I try to seed my data. The join table "will only accept" a combination of two out of the three join keys. I cannot get all three foreign keys into the join table at the same time.
mystox_db=# SELECT * FROM ownerships; createdAt | updatedAt | userId | stockId -----------+-----------+---------+---------
mystox_db=# SELECT * FROM ownerships; createdAt | updatedAt | groupId | stockId -----------+-----------+---------+---------
mystox_db=# SELECT * FROM ownerships; createdAt | updatedAt | userId | groupId -----------+-----------+--------+---------
What's a Group?
In mathematics, a group is an algebraic structure... just kidding
So we want to have stocks organized into groups (watchlist, portfolio, sold, etc) and each user will have a group. We originally thought adding the groups as a string in the join table but decided we wanted to create a separate table for groups so that we can add more later.
How many groups will a user have? Just one? Or many?
A user will have many groups.
Weird. I have to go to a meeting, but I'll respond when I'm back. Go to lunch!
lunch? We're not familiar with that framework?
I've been playing around with this, and I'm not sure Sequelize really lets one model have many belongToManys. So I'd say groups should be a string in your table, the way you were originally thinking. You can totally add more later; I presume you're going to let the user select a group from a dropdown or something? Just add more groups to the dropdown.
I'm going to close this. Feel free to open a new one linking to this if need be!
We want to create a join table that has three foreign keys, which seems like it could potentially be a bad idea but as of right now we can't see anything wrong with it.
Basically we tried many combinations of relationships in sequelize and ran a migration. The join table will only accept two foreign keys. We have been able to get every combination of two out of three foreign keys into the join table but have not been able to get all three.
Stock.belongsToMany(User, {through: Ownership}); User.belongsToMany(Stock, {through: Ownership}); Stock.belongsToMany(Group, {through: Ownership}); Group.belongsToMany(Stock, {through: Ownership});