@@ -1473,6 +1473,7 @@ export class ZodSchemaFactory<
14731473 fieldSchema ,
14741474 z
14751475 . object ( {
1476+ // TODO: use Decimal/BigInt for incremental updates
14761477 set : this . nullableIf ( z . number ( ) . optional ( ) , ! ! fieldDef . optional ) . optional ( ) ,
14771478 increment : z . number ( ) . optional ( ) ,
14781479 decrement : z . number ( ) . optional ( ) ,
@@ -1694,7 +1695,7 @@ export class ZodSchemaFactory<
16941695
16951696 // fields used in `having` must be either in the `by` list, or aggregations
16961697 schema = schema . refine ( ( value : any ) => {
1697- const bys = typeof value . by === 'string' ? [ value . by ] : value . by ;
1698+ const bys = enumerate ( value . by ) ;
16981699 if ( value . having && typeof value . having === 'object' ) {
16991700 for ( const [ key , val ] of Object . entries ( value . having ) ) {
17001701 if ( AggregateOperators . includes ( key as any ) ) {
@@ -1721,17 +1722,18 @@ export class ZodSchemaFactory<
17211722
17221723 // fields used in `orderBy` must be either in the `by` list, or aggregations
17231724 schema = schema . refine ( ( value : any ) => {
1724- const bys = typeof value . by === 'string' ? [ value . by ] : value . by ;
1725- if (
1726- value . orderBy &&
1727- Object . keys ( value . orderBy )
1728- . filter ( ( f ) => ! AggregateOperators . includes ( f as AggregateOperators ) )
1729- . some ( ( key ) => ! bys . includes ( key ) )
1730- ) {
1731- return false ;
1732- } else {
1733- return true ;
1725+ const bys = enumerate ( value . by ) ;
1726+ for ( const orderBy of enumerate ( value . orderBy ) ) {
1727+ if (
1728+ orderBy &&
1729+ Object . keys ( orderBy )
1730+ . filter ( ( f ) => ! AggregateOperators . includes ( f as AggregateOperators ) )
1731+ . some ( ( key ) => ! bys . includes ( key ) )
1732+ ) {
1733+ return false ;
1734+ }
17341735 }
1736+ return true ;
17351737 } , 'fields in "orderBy" must be in "by"' ) ;
17361738
17371739 return schema as ZodType < GroupByArgs < Schema , Model , Options , ExtQueryArgs > > ;
0 commit comments