This repository was archived by the owner on Sep 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -157,7 +157,8 @@ Note that all this eager related options are optional.
157157
158158#### Query Operators
159159
160- - ** ` $modify ` ** - modifiers allow you to easily reuse snippets of query logic. See
160+ - ** ` $modify ` ** - modifiers allow you to easily reuse snippets of query logic. you can pass arguments and use
161+ multiple modifiers. value can be array, a serialized JSON array or a string with modifiers separated by ` , ` . See
161162 [ ` modify ` ] ( https://vincit.github.io/objection.js/api/query-builder/other-methods.html#modify ) documentation.
162163
163164- ** ` $eager ` ** - eager load relations defined in models' ` relationMappings ` getter methods. See
Original file line number Diff line number Diff line change @@ -305,7 +305,11 @@ class Service extends AdapterService {
305305 }
306306
307307 if ( query && query . $modify ) {
308- q . modify ( ...query . $modify ) ;
308+ if ( typeof query . $modify === 'string' ) {
309+ if ( query . $modify [ 0 ] === '[' && query . $modify [ query . $modify . length - 1 ] === ']' ) { q . modify ( ...JSON . parse ( query . $modify ) ) ; } else { q . modify ( query . $modify . split ( ',' ) ) ; }
310+ } else {
311+ q . modify ( ...query . $modify ) ;
312+ }
309313
310314 delete query . $modify ;
311315 }
Original file line number Diff line number Diff line change @@ -1690,6 +1690,27 @@ describe('Feathers Objection Service', () => {
16901690 } ) ;
16911691 } ) ;
16921692
1693+ it ( 'allow $modify query as string' , ( ) => {
1694+ return companies . find ( { query : { $modify : 'google' } } ) . then ( data => {
1695+ expect ( data . length ) . to . be . equal ( 1 ) ;
1696+ expect ( data [ 0 ] . name ) . to . be . equal ( 'Google' ) ;
1697+ } ) ;
1698+ } ) ;
1699+
1700+ it ( 'allow $modify query as string with multiple modifiers' , ( ) => {
1701+ return companies . find ( { query : { $modify : 'apple,large' } } ) . then ( data => {
1702+ expect ( data . length ) . to . be . equal ( 1 ) ;
1703+ expect ( data [ 0 ] . name ) . to . be . equal ( 'Apple' ) ;
1704+ } ) ;
1705+ } ) ;
1706+
1707+ it ( 'allow $modify query as string array' , ( ) => {
1708+ return companies . find ( { query : { $modify : JSON . stringify ( [ 'google' ] ) } } ) . then ( data => {
1709+ expect ( data . length ) . to . be . equal ( 1 ) ;
1710+ expect ( data [ 0 ] . name ) . to . be . equal ( 'Google' ) ;
1711+ } ) ;
1712+ } ) ;
1713+
16931714 it ( 'allow $modify query with args' , ( ) => {
16941715 return companies . find ( { query : { $modify : [ 'large' , false ] } } ) . then ( data => {
16951716 expect ( data . length ) . to . be . equal ( 1 ) ;
You can’t perform that action at this time.
0 commit comments