I need to do something like this. Where you can put a alias in front of the column name. o. c. etc
SELECT o.OrderID, o.OrderDate, c.CustomerName FROM...
Here is the entire query im trying to replicate in sequelize
SELECT c.id AS comment_id, c.comment, r.id AS reply_id, r.parent_comment_id, r.comment AS reply_comment FROM (comments c) LEFT JOIN comments r ON c.id = r.parent_comment_id
What I tried
attributes: ['c.id', ['comment_id'], 'c.comment', 'r.id', ['reply_id'], 'r.parent_comment_id', 'r.comment', ['reply_comment']]
Documentation from sequelize only shows how to do one attribute
Model.findAll({
attributes: ['foo', ['baz']]
});
SELECT foo AS baz ...
Each field you want an alias to, you need to pass as a two position array.
Model.findAll({
attributes: [
'foo', // do not use alias
['bar', 'baz'], // uses alias 'baz' for column 'bar'
[Sequelize.col('related.foo'), 'related_foo'] // alias on includes
],
includes: [
{
model: related,
attributes: [] // empty to not generate nested atributes.
}
]
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With