How to implement many to many association in sequelize

前端 未结 4 670
庸人自扰
庸人自扰 2020-11-27 09:33

I have two tables: Books and Articles with a many-to-many relationship between them. Joining table is BookArticles.

models/books.js

module.exports =          


        
4条回答
  •  借酒劲吻你
    2020-11-27 09:51

    delete BookArticles model and update relation to:

    m.Book.hasMany(m.Article, {through: 'book_articles'});
    m.Article.hasMany(m.Books, {through: 'book_articles'});
    

提交回复
热议问题