Saturday, 10 June 2017

Sequelize ORM:MySql Hasmany associations in different model files

sequelize docs(http://docs.sequelizejs.com/manual/tutorial/associations.html#one-to-many-associations) doesn't say about how to write associations in different model files

for eg

models/user.js

module.exports = {

    options: {
        tableName: 'users',
        classMethods: {

        },
        hooks: {},
        timestamps: false
    }

};

models/amount.js

module.exports = {

    options: {
        tableName: 'amount',
        timestamps: false
    }
};

one user has so many amounts so i would like to write a hasmany relation to get all the amount to particular user

Currently my controller look like this

Test.findAll().then(function (result,err) {
       console.log(result);
});



via Jabaa

No comments:

Post a Comment