duplicate foreignKey when using sequelize.sync()
tonghoai opened this issue · 3 comments
tonghoai commented
remjx commented
Each belongsTo and hasMany creates one foreign key. It may make sense to
use both in situations like this so you can run joins both ways Sequelize
querying syntax. If you'll only need to join A to B and not B to A, you
don't need both. At least that is my understanding.
…On Tue, Mar 26, 2019, 12:38 AM tonghoai ***@***.***> wrote:
I'm using models like files in models folder. But when i'm using
sequelize.sync() some models duplicated foreginKey like following
[image: image]
<https://user-images.githubusercontent.com/10321465/54971858-187f8600-4fbb-11e9-8d9f-6607319cda16.png>
This is my associate
[image: image]
<https://user-images.githubusercontent.com/10321465/54971889-449b0700-4fbb-11e9-83b0-ed1e199f0ff8.png>
[image: image]
<https://user-images.githubusercontent.com/10321465/54971899-5ed4e500-4fbb-11e9-9ad1-5b56667575a3.png>
[image: image]
<https://user-images.githubusercontent.com/10321465/54971908-6a281080-4fbb-11e9-8964-568f210ab9ed.png>
[image: image]
<https://user-images.githubusercontent.com/10321465/54971916-7613d280-4fbb-11e9-9051-f09b6b9a49d6.png>
Have 3 foreginKey but sequelize has created 6 foreginKey. Anybody can help
me? Thank you!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#90>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AhfqFUzgJJ60L4wsFytTw1IH2WUROsp7ks5vaaRBgaJpZM4cKlYw>
.
tonghoai commented
Each belongsTo and hasMany creates one foreign key. It may make sense to use both in situations like this so you can run joins both ways Sequelize querying syntax. If you'll only need to join A to B and not B to A, you don't need both. At least that is my
I tried removing belongsTo and it works, but duplicator only appears in some models, awesome!