Answer the question
In order to leave comments, you need to log in
How to limit selection of fields from nested schemas in sequelize?
I can't restrict field selection from sequelize nested schemas, I try like this:
models.template.findById(req.params.id, {
include: [{
model: models.templateMessage,
separate: true, // это я уже от безысходности, и так и так не работает :(
arrtibutes: {exclude: ['data']},
order: ['order']
}]
});
Answer the question
In order to leave comments, you need to log in
const model = models.template;
// тут получаешь все поля объекта
const fields = Object.keys(model.attributes).map(key => model.attributes[key].field);
// можешь уже отсечь ненужное или отсортировать
...
const attributes = myFields;
// запрос
models.template.findById(req.params.id, {
include: [{
model: models.templateMessage,
// тут указано какие поля тебе нужны
attributes,
order: ['order']
}]
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question