Skip to content

Commit 9f05cde

Browse files
author
NarrowsProjects
committed
EXPERIMENT: convert back to object syntax if no explicit columns were defined
1 parent c95af60 commit 9f05cde

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

lib/database/utilities/QueryBuilder.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -626,23 +626,12 @@ class QueryBuilder {
626626
*/
627627
toImplementation(model) {
628628
const options = { ...this.options };
629-
const hasColumns = options.attributes.some((attribute) => typeof attribute === 'string');
629+
const hasExplicitColumns = options.attributes.some((attribute) => typeof attribute === 'string');
630630

631631
if (!this._selectOnly) {
632-
if (!hasColumns) {
633-
this.setModel(model);
634-
const attributes = Object.keys(this.model.rawAttributes);
635-
options.attributes = options.attributes.concat(attributes);
636-
}
637-
}
638-
639-
const primaryKey = model.primaryKeyAttribute;
640-
641-
if (primaryKey) {
642-
const alreadyOrdered = options.order?.some(([column]) => column === primaryKey);
643-
644-
if (!alreadyOrdered) {
645-
this.orderBy(primaryKey, 'ASC');
632+
if (!hasExplicitColumns) {
633+
// Convert to object syntax — Sequelize will include all model columns by default
634+
options.attributes = { include: options.attributes };
646635
}
647636
}
648637

0 commit comments

Comments
 (0)