简体   繁体   中英

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:

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

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,
    }],
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM