Reputation: 1797
In my model definition I have:
tableA.hasMany(tableB);
So in tableB I have the field "tableAId".
However, when I try to run this code:
return models.tableB.findAll({include: {model: models.tableA}}).then(function(result){
if(result){
return Promise.resolve(result);
}
else{
return Promise.reject(false);
}
}).catch(function(err){
console.log(err);
return Promise.reject(err);
});
I get the error:
A is not associated with B
So defining that tableA has many tableB is not enough in order to join the tables?
Upvotes: 0
Views: 1193
Reputation: 7401
You need to create belongsTo
association inside tableB
model, referencing tableA
.
tableB.belongsTo(tableA);
Then you will be able to include tableA
while querying tableB
.
Upvotes: 1