Skip to content Skip to sidebar Skip to footer

Create A Record And An Associated Record In One Go

The Problem: Imagine I have two associated models, Library which has many Books: var Library = sequelize.define('Library', { title: Sequelize.STRING, description: Sequelize

Solution 1:

Your desired behavior can be achieved by adding the include option to the create parameters like so:

Library.create({
    name: 'Roan Library',
    address: '123 Any St',
    Books: [
        {
            title: 'Reading with Time',
            description: 'A fun jaunt in reading'
        }
    ]
}, {
    include : [Book]
});

Post a Comment for "Create A Record And An Associated Record In One Go"