Sequelize hasMany association not working properly
<p>Something is wrong with my code and I can't find where it is.
I'm using Sequelize on my node server.
It seems like i can't make belongsTo association work.</p>

<p>Here is the error I catch from the promise:</p>

<blockquote>
  <p>[TypeError: Property 'setDetails' of object [object
  SequelizeInstance:car] is not a function]</p>
</blockquote>

<p>Actually what it does is INSERT the detail data but without the car_id and it does not INSERT data in car table.</p>

<p>And here is what I have:</p>

<p>models/detail.js file:</p>

<pre><code>var Detail = pg.sequelize.define('details', {
        color: {
            type: pg.Sequelize.STRING,
            allowNull: false
        }
    }, {
        timestamps: false,
        underscored: true
    }
);

module.exports = Detail;
</code></pre>

<p>models/car.js</p>

<pre><code>var Detail  = require('../models/detail');
var Car = pg.sequelize.define('cars', {
        id: {
            type: pg.Sequelize.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        title: {
            type: pg.Sequelize.STRING,
            allowNull: false
        }
    }, {
        underscored: true
    }
);
var c = Detail.belongsTo(Car, {
    as: 'detail',
    foreignKey: 'car_id',
    onDelete: 'CASCADE'
});
Car.c = c;
module.exports = Car;
</code></pre>

<p>router/car.js</p>

<pre><code>var Car  = require('../models/car');
router.post('/add', function(req, res, next) {

    var createData = {
        title: req.body.title,
        detail: {
            color: req.body.color
        }
    };

    Car.create(createData, { include: [ Car.c ] })
        .then(function(result) {
            res.status(200).json(result);
        })
        .catch(function(err) {
            console.log(err);
        });

});

module.exports = router;
</code></pre>

<p>I have been able to make an hasMany association but not this one.</p>

<p>What's wrong with my code ?</p>