By reading source code on the sequelize I found the solution, Utils.mapFinderOptions
and model._injectScope
const model = MyModel.scope(scopes);
const { queryGenerator } = model;
const queryOptions = {
scopes,
attributes,
include,
where,
order,
offset,
limit,
};
model._injectScope(queryOptions);
model._validateIncludedElements.bind(model)(queryOptions);
Utils.mapFinderOptions(queryOptions, model);
const cte = queryGenerator.selectQuery(
model.getTableName(),
queryOptions,
model
)
.slice(0, -1);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…