Friday 24 February 2017

Sequelize ORM Question

Let's assume I have 2 tables: author and books. Let us then say that there is a many-to-many relationship between books and authors. Author.belongsToMany(Book, { through: 'AuthorBook', foreignKey: 'authorId' }); Book.belongsToMany(Author, { through: 'AuthorBook', foreignKey: 'bookId' }); So this results in a join table, named 'AuthorBook.' But I thought this join table was supposed to automatically populate itself as I create entries for Author and Book tables individually. Rather no row gets created for the join table. As I create a new Book entry for example, isn't the join table supposed to automatically create a row of its own as it references the Book table to the author table? Is that not the whole point of having join tables in the first place?edit: for clarification

Submitted February 25, 2017 at 06:03AM by LeahIsBest

No comments:

Post a Comment