Can't exclude association's fields from select statement in sequelize
I'm going to answer myself as it might be useful to someone in future. So according to #3664, #2974 and #2975 the answer is the following (thanks to mickhansen):
include: [{
model: dbcontext.item,
as: 'items',
attributes: ['spn'],
through: {
attributes: []
}
}]
And soon it will be documented.
I realize this thread is a bit outdated, but since this is high in the Google search results and I struggled to find the answer myself, I thought I'd add this here.
If you're using Model.getAssociatedModel()
or Model.$get()
(for sequelize-typescript), the current answers listed will not work for this use case. In order to hide the model associations you need to add joinTableAttributes: []
Example:
Model.getAssociatedModel({
joinTableAttributes: []
})
Example:
Model.$get('property', <any>{
joinTableAttributes: []
});
At the time of this post, joinTableAttributes
is not included in the sequelize-typescript types hence the <any>