Sequelize one to one relation

不羁岁月 提交于 2019-12-06 04:20:02
Ellebkey

You don't need to set belongTo and hasMany as you show at first. Use only one depending on your db schema.

For get FirstFrameId and LastFrameId on the Videos Model you need to use:

Video.belongsTo(Frame, {as: 'FirstFrame'});
Video.belongsTo(Frame, {as: 'LastFrame'});

This is specify on the Sequelize docs and you can check it here

"Even though it is called a HasOne association, for most 1:1 relations you usually want the BelongsTo association since BelongsTo will add the foreignKey on the source where hasOne will add on the target."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!