Saturday, 3 June 2017

Sequelize one-to-many query (with include) produces X is not associated to Y

so i'm having problems with sequelize's one to many relationship, my associations are defined like this:

X.hasMany(Y, { as: 'X' });
Y.belongsTo(X, { as: 'Ys' });

and my findAll is here:

return X.findAll(
        {
            where: {
                something: something,
            },
            include: [{ model: db.Y, as: 'Ys' }]
        }
    );

and this is producing the error:

"error": "Y (Ys) is not associated to X!"

Not quite sure what i'm doing wrong here :/



via H0pesfall

No comments:

Post a Comment