我有一个Sequelize findAll()方法,可以在一些连接和过滤器之后获取记录。原始SQL正在转换为Sequelize ORM查询。 Sequelize ORM运行的查询如下:
SELECT
`tableA`.*
FROM
(SELECT
`tableA`.`i_id`,
COUNT(
DISTINCT (
tableA.c_id
)
) AS `total`,
`ModelB`.`title` AS `ModelB.title`,
`ModelB`.`id` AS `ModelB.id`
FROM
`tableA` AS `aliasA`
INNER JOIN `tableB` AS `aliasB`
ON `aliasA`.`c_id` = `aliasB`.`id`
INNER JOIN `tableC` AS `aliasC`
ON `aliasA`.`clientID` = `aliasC`.`id`
AND `aliasC`.`a` = '483'
AND `aliasC`.`s` IN (0, '', NULL)
INNER JOIN `tableD` AS `aliasD`
ON `aliasA`.`id` = `aliasD`.`id`
AND `aliasD`.`id` IN (100, 101)
WHERE `aliasA`.`state` = 'on'
AND (
`aliasA`.`time_added` >= '2012-02-01 00:00:00'
AND `aliasA`.`time_added` <= '2017-08-24 12:31:13'
)
LIMIT 100) AS `aliasA`
INNER JOIN `tableE` AS `aliasE`
ON `aliasD.uid` = `aliasE`.`uid`
AND `aliasD`.`object_id` = '483'
LEFT OUTER JOIN `tableF` AS `aliasF`
ON `aliasA`.`id` = `aliasF`.`uid`
AND `aliasF`.`share` IN (100, 101);
我的要求是首先应用所有连接,然后通过将AND和OR应用WHERE子句来过滤。最后,我需要在关联表的coluns上应用'Group','Order'和'Limit'子句。请让我理解,我是Node世界的新手。我在Sequelize官方文档中找不到这样的东西。