Tuesday, 2 May 2017

Sequelize one to one relation

I have two models, Video and Frame.

Frame.belongsTo(models.Video);
Video.hasMany(models.Frame, { as: "Frames" });

I now need a way to specify first and last frame for a video, but can't get it to work.

I tried this:

Video.hasOne(Frame, { as: "FirstFrame" });
Video.hasOne(Frame, { as: "LastFrame" });

but that creates FirstFrameId and LastFrameId in the Frames table instead of the Videos table. I need to have video.get/setFirstFrame() and video.get/setLastFrame() functions available. How can I do this?



via MartinP

No comments:

Post a Comment