@@ -12,6 +12,7 @@ import { Model } from '../model/Model'
1212import { Connection } from '../connection/Connection'
1313import {
1414 Where ,
15+ WherePrimaryClosure ,
1516 WhereSecondaryClosure ,
1617 Order ,
1718 OrderDirection ,
@@ -80,9 +81,10 @@ export class Query<M extends Model = Model> {
8081 /**
8182 * Add a basic where clause to the query.
8283 */
83- where < T extends keyof M > ( field : T , value : WhereSecondaryClosure < M , T > ) : this
84- where < T extends keyof M > ( field : T , value : M [ T ] | M [ T ] [ ] ) : this
85- where ( field : any , value : any ) : any {
84+ where < T extends keyof M > (
85+ field : WherePrimaryClosure < M > | T ,
86+ value ?: WhereSecondaryClosure < M , T > | M [ T ] | M [ T ] [ ]
87+ ) : this {
8688 this . wheres . push ( { field, value, boolean : 'and' } )
8789
8890 return this
@@ -107,9 +109,10 @@ export class Query<M extends Model = Model> {
107109 /**
108110 * Add an "or where" clause to the query.
109111 */
110- orWhere < T extends keyof M > ( field : T , value : WhereSecondaryClosure < M , T > ) : this
111- orWhere < T extends keyof M > ( field : T , value : M [ T ] | M [ T ] [ ] ) : this
112- orWhere ( field : any , value : any ) : any {
112+ orWhere < T extends keyof M > (
113+ field : WherePrimaryClosure < M > | T ,
114+ value ?: WhereSecondaryClosure < M , T > | M [ T ] | M [ T ] [ ]
115+ ) : this {
113116 this . wheres . push ( { field, value, boolean : 'or' } )
114117
115118 return this
@@ -273,6 +276,10 @@ export class Query<M extends Model = Model> {
273276 * The function to compare where clause to the given model.
274277 */
275278 protected whereComparator ( model : M , where : Where < M , any > ) : boolean {
279+ if ( isFunction ( where . field ) ) {
280+ return where . field ( model )
281+ }
282+
276283 if ( isArray ( where . value ) ) {
277284 return where . value . includes ( model [ where . field ] )
278285 }
0 commit comments