A query is a self-joined sentence with one table as follows:
SELECT cat.cat_id, cat.cat_name, sub_cat.cat_id, sub_cat.cat_name
FROM Categories AS cat
LEFT JOIN Categories AS sub_cat
ON sub_cat.parent = cat.cat_id;
Even if you look at the official document, you can name it in the column, but you can't name it on the table. I need help ㅠ<
orm sequelize.js mysql sql database
So subcategories find their own categories, right? I found out that Sequelize has include
option. I'm not sure if this will be a hint.
// This code has not been tested. It may not work.
models.categories.find({
include: [
{
model: models.categories,
as: 'sub_cat'
}
],
where: {
cat_id: sub_cat.parent
}
}).then(function(result) { /* something... */ });
If it doesn't work out, I think you can fly Nalquery .
© 2024 OneMinuteCode. All rights reserved.