[英]Using literal in include (literal join) with sequelize
I have a problem implementing a join to stored procedure that return a table, The problem is: I have a stored procedure who returns me one uuid (and others fields), To apply as a filter to the real query I thought to use an Inner join, example:我在实现连接到返回表的存储过程时遇到问题,问题是:我有一个存储过程,它返回一个 uuid(和其他字段),作为过滤器应用于我认为使用 Inner 的真实查询加入,例如:
SELECT
ot.*
FROM
"OriginalTable" as ot
INNER JOIN "MyStoredProcedures"(param1, params2) as enableds
ON ot.uuid = enableds.uuid
...
Something like:就像是:
OriginalModel.findAll({
include: [{
model: sequelize.fn('MyStoredProcedures', param1, param2),
required: true,
}],
});
But I realized it isn't supported, getting:但我意识到它不受支持,得到:
TypeError: include.model.getTableName is not a function类型错误:include.model.getTableName 不是 function
There are some way to do an inner join with a literal like value?有一些方法可以使用类似文字的值进行内部连接?
Thanks, sorry my poor english谢谢,对不起我的英语不好
you can call the stored procedure and then make your join:您可以调用存储过程,然后加入:
const newTable = await sequelize.query(
'CALL MyStoredProcedures (:param1, :param2)',
{replacements: { param1: "value1", param2: "value2", }}
)
OriginalModel.findAll({
include: [{
model: newTable,
required: true,
}],
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.