Ian Grainger
Ian Grainger

Reputation: 5516

Get children from parent Sequelize

If I have:

var Game = Sequelize.define('game');
var Move = Sequelize.define('move');
Move.belongsTo(Game);

How do I get a set of games with all moves? It seems I can easily get all moves with games:

Move.findAll({include: Game});

But not the other way around?

Game.findAll({include: Move});

Gives me Unhandled rejection Error: Move (move) is not associated to game!.

Upvotes: 1

Views: 2293

Answers (1)

Jan Aagaard Meier
Jan Aagaard Meier

Reputation: 28778

You need to provide the association both ways

Game.hasMany(Move);

Upvotes: 3

Related Questions