website icon indicating copy to clipboard operation
website copied to clipboard

docs: fix incorrect example of attributes in SELECT query docs

Open emad-saud opened this issue 11 months ago • 1 comments

Under the heading "Specifying attributes for SELECT queries" in the "Model Querying - Basics" documentation page, the example incorrectly used:

Model.findAll({
  attributes: ['foo', ['bar', 'baz'], 'qux'],
});

which would cause a runtime error. Updated it to the correct format:

Model.findAll({
  attributes: [['foo', 'baz'], ['baz', 'qux']],
});

to properly map field names to aliases.

Also fixed a similar issue in the next example on the same page, which used the same incorrect structure for the attributes option, the previous example showed:

Model.findAll({
  attributes: ['foo', [sequelize.fn('COUNT', sequelize.col('hats')), 'n_hats'], 'bar'],
});

which causes the same runtime error. Updated it to the right format:

Model.findAll({
  attributes: [['foo', 'bar'], [sequelize.fn('COUNT', sequelize.col('hats')), 'n_hats']],
});

These correction ensures valid syntax and clearer guidance for Sequelize users.

emad-saud avatar Apr 12 '25 11:04 emad-saud