I have a sequelize query with multiple where conditions in an include model:
const scrapingUrl = await db.ScrapingUrl.findOne({
where: strong text{
date_downloaded: null,
},
include: [ {
model: db.Action,
where: {
$or: {
hourly_scraping_limit: null,
scraping_counter: {
$or: {
$eq: null,
$lt: Sequelize.literal('Action.hourly_scraping_limit')
}
}
},
$or: {
hourly_scraping_limit_per_proxy: null,
scraping_counter_per_proxy: {
$or: {
$eq: null,
$lt: Sequelize.literal('Action.hourly_scraping_limit_per_proxy')
}
}
}
},
include: [ db.ScrapingContainer ]
} ]
});
It seems to ignore hourly_scraping_limit part and only filters for hourly_scraping_limit_per_proxy. The relevant query part is this:
$or: {
hourly_scraping_limit: null,
scraping_counter: {
$or: {
$eq: null,
$lt: Sequelize.literal('Action.hourly_scraping_limit')
}
}
},
Sequelize logs the following SQL statement:
SELECT `ScrapingUrl`.`id`, `ScrapingUrl`.`action_id`, `ScrapingUrl`.`url`, `ScrapingUrl`.`date_added`, `ScrapingUrl`.`date_downloaded`, `ScrapingUrl`.`date_scraped`, `ScrapingUrl`.`success_pattern_found`, `ScrapingUrl`.`blocked_pattern_found`, `ScrapingUrl`.`scraping_blob_id`, `Action`.`id` AS `Action.id`, `Action`.`name` AS `Action.name`, `Action`.`scraping_container_id` AS `Action.scraping_container_id`, `Action`.`hourly_scraping_limit` AS `Action.hourly_scraping_limit`, `Action`.`hourly_scraping_limit_per_proxy` AS `Action.hourly_scraping_limit_per_proxy`, `Action`.`scraping_counter` AS `Action.scraping_counter`, `Action`.`scraping_counter_per_proxy` AS `Action.scraping_counter_per_proxy`, `Action`.`scraping_counter_last_reset` AS `Action.scraping_counter_last_reset`, `Action`.`scraping_success_pattern` AS `Action.scraping_success_pattern`, `Action`.`scraping_blocked_pattern` AS `Action.scraping_blocked_pattern`, `Action.ScrapingContainer`.`id` AS `Action.ScrapingContainer.id`, `Action.ScrapingContainer`.`name` AS `Action.ScrapingContainer.name` FROM `scraping_urls` AS `ScrapingUrl` INNER JOIN `actions` AS `Action` ON `ScrapingUrl`.`action_id` = `Action`.`id` AND ((`Action`.`hourly_scraping_limit_per_proxy` IS NULL OR (`Action`.`scraping_counter_per_proxy` IS NULL OR `Action`.`scraping_counter_per_proxy` < Action.hourly_scraping_limit_per_proxy))) LEFT OUTER JOIN `scraping_containers` AS `Action.ScrapingContainer` ON `Action`.`scraping_container_id` = `Action.ScrapingContainer`.`id` WHERE `ScrapingUrl`.`date_downloaded` IS NULL LIMIT 1;