@@ -477,9 +477,46 @@ export abstract class WhereBaseBuilder<
477477 column1 : string ,
478478 column2 : string | string [ ] ,
479479 ) {
480- const conditionsArray = this . _pendingConditions . concat ( conditions ) ;
480+ // TODO: verificar se colunas não são condition, para remover a condition
481+ let conditionsArray = this . _pendingConditions . concat ( conditions ) ;
481482 this . _pendingConditions = [ ] ;
482- return this . buildConditions ( conditionsArray , column1 , column2 ) ;
483+ const isConditionIsNullInColumn2 = column2 === Condition . IsNull ;
484+ if ( isConditionIsNullInColumn2 ) {
485+ conditionsArray = this . conditionIsNull ( conditionsArray ) ;
486+ }
487+ // const isConditionInColumn2 = this.isEqualAnyCondition(column2);
488+ return this . buildConditions (
489+ conditionsArray ,
490+ column1 ,
491+ isConditionIsNullInColumn2 ? void 0 : column2 ) ;
492+ }
493+
494+ private conditionIsNull ( currentConditions : Condition [ ] ) : Condition [ ] {
495+ // new scope
496+ if ( ! currentConditions || ( currentConditions . length === 1 && currentConditions [ 0 ] === void 0 ) ) {
497+ return [ Condition . IsNull ] ;
498+ }
499+ switch ( currentConditions . toString ( ) ) {
500+ case [ Condition . Equal ] . toString ( ) :
501+ return [ Condition . IsNull ] ;
502+ case [ Condition . Not , Condition . Equal ] . toString ( ) :
503+ return [ Condition . Not , Condition . IsNull ] ;
504+ default :
505+ return currentConditions ;
506+ }
507+ }
508+
509+ private isEqualAnyCondition ( value : string | string [ ] ) : boolean {
510+ if ( Array . isArray ( value ) ) {
511+ for ( const v of value ) {
512+ const r = this . isEqualAnyCondition ( v ) ;
513+ if ( r ) {
514+ return true ;
515+ }
516+ }
517+ return false ;
518+ }
519+ return ( Object as any ) . values ( Condition ) . filter ( ( x : string ) => x === value ) . length > 0 ;
483520 }
484521
485522 private buildConditions (
0 commit comments