@@ -397,11 +397,10 @@ class WhereAssociationQueryBuilder extends WhereQueryBuilder {
397397 * @param {QueryBuilder } queryBuilder The include expression.
398398 * @param {string } association The target association.
399399 * @param {string } column The target column.
400- * @param {boolean } required If the association must exist.
401400 */
402- constructor ( sequelize , queryBuilder , association , column , required = true ) {
401+ constructor ( sequelize , queryBuilder , association , column ) {
403402 super ( queryBuilder , column ) ;
404- this . required = required ;
403+
405404 this . _sequelize = sequelize ;
406405
407406 this . association = association ;
@@ -414,18 +413,13 @@ class WhereAssociationQueryBuilder extends WhereQueryBuilder {
414413 * @returns {QueryBuilder } The current QueryBuilder instance.
415414 */
416415 _op ( operation ) {
417- const association = this . queryBuilder . options . include ?. find ( ( { association } ) => association === this . association ) ;
418-
419- if ( association ) {
420- association . where = { [ this . column ] : operation } ;
421- association . required = this . required ;
422- } else {
423- this . queryBuilder . include ( {
424- association : this . association ,
425- required : this . required ,
426- where : { [ this . column ] : operation } ,
427- } ) ;
428- }
416+ this . queryBuilder . include ( {
417+ association : this . association ,
418+ required : true ,
419+ where : {
420+ [ this . column ] : operation ,
421+ } ,
422+ } ) ;
429423
430424 return this . queryBuilder ;
431425 }
@@ -441,8 +435,7 @@ class QueryBuilder {
441435 */
442436 constructor ( sequelize ) {
443437 this . _sequelize = sequelize ;
444- this . options = { where : { } , replacements : { } , attributes : [ ] } ;
445- this . _selectOnly = false ;
438+ this . options = { where : { } , replacements : { } } ;
446439 }
447440
448441 /**
@@ -460,32 +453,6 @@ class QueryBuilder {
460453 return this ;
461454 }
462455
463- /**
464- * Include association for expression lists
465- *
466- * @param {Array<object|function<sequelize, object>> } expressions The include expression list.
467- * @returns {QueryBuilder } this.
468- */
469- includeAll ( expressions ) {
470- expressions . forEach ( ( expression ) => this . include ( expression ) ) ;
471- return this ;
472- }
473-
474- /**
475- * Pushes raw order objects to the top level order array
476- *
477- * @param {Array<object|function<sequelize, object>> } orders List of orders to be pushed.
478- * @returns {QueryBuilder } this.
479- */
480- pushOrders ( orders ) {
481- if ( ! this . options . order ) {
482- this . options . order = [ ] ;
483- }
484-
485- this . options . order = this . options . order . concat ( orders ) ;
486- return this ;
487- }
488-
489456 /**
490457 * The numbers of items to return.
491458 *
@@ -551,50 +518,16 @@ class QueryBuilder {
551518 * @return {QueryBuilder } this
552519 */
553520 includeAttribute ( { query, alias } ) {
554- this . options . attributes . push ( [
521+ if ( ! this . options . attributes ) {
522+ this . options . attributes = { include : [ ] } ;
523+ }
524+ this . options . attributes . include . push ( [
555525 typeof query === 'function' ? query ( this . _sequelize ) : this . _sequelize . literal ( query ) ,
556526 alias ,
557527 ] ) ;
558528 return this ;
559529 }
560530
561- /**
562- * Prevents toImplementation from automatically appending all model columns
563- * when no explicit string columns are selected.
564- *
565- * @return {QueryBuilder } this
566- */
567- selectOnly ( ) {
568- this . _selectOnly = true ;
569- return this ;
570- }
571-
572- /**
573- * Set which top-level columns to fetch
574- *
575- * @param {string[] } columns The column names to select.
576- * @returns {QueryBuilder } this
577- */
578- selectAttributes ( columns ) {
579- const existing = this . options . attributes . map ( ( attribute ) => {
580- if ( Array . isArray ( attribute ) ) {
581- return attribute [ 1 ] ; // Return the alias instead of the expression
582- }
583-
584- return attribute ;
585- } ) ;
586-
587- for ( const column of columns ) {
588- if ( existing . includes ( columns ) ) {
589- throw new Error ( `Column ${ column } allready exists in attributes: ${ existing . join ( ) } ` ) ;
590- }
591-
592- this . options . attributes . push ( column ) ;
593- }
594-
595- return this ;
596- }
597-
598531 /**
599532 * Generic Key-Value pair setter.
600533 *
@@ -621,32 +554,10 @@ class QueryBuilder {
621554 /**
622555 * Returns the implementation specific query.
623556 *
624- * @param {string|Model } model The Sequelize model to reference.
625557 * @returns {Object } Implementation specific query.
626558 */
627- toImplementation ( model ) {
628- const options = { ...this . options } ;
629- const hasColumns = options . attributes . some ( ( attribute ) => typeof attribute === 'string' ) ;
630-
631- 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' ) ;
646- }
647- }
648-
649- return options ;
559+ toImplementation ( ) {
560+ return this . options ;
650561 }
651562
652563 /**
@@ -715,11 +626,10 @@ class QueryBuilder {
715626 *
716627 * @param {string } association The target association.
717628 * @param {string } column The target column.
718- * @param {boolean } required If the association must exist.
719629 * @returns {WhereAssociationQueryBuilder } The current QueryBuilder instance.
720630 */
721- whereAssociation ( association , column , required ) {
722- return new WhereAssociationQueryBuilder ( this . _sequelize , this , association , column , required ) ;
631+ whereAssociation ( association , column ) {
632+ return new WhereAssociationQueryBuilder ( this . _sequelize , this , association , column ) ;
723633 }
724634}
725635
0 commit comments