@@ -154,21 +154,23 @@ class Service extends AdapterService {
154154 * @param params
155155 * @param parentKey
156156 * @param methodKey
157+ * @param allowRefs
157158 */
158- objectify ( query , params , parentKey , methodKey ) {
159+ objectify ( query , params , parentKey , methodKey , allowRefs ) {
159160 if ( params . $eager ) { delete params . $eager ; }
160161 if ( params . $joinEager ) { delete params . $joinEager ; }
161162 if ( params . $joinRelation ) { delete params . $joinRelation ; }
162163 if ( params . $modifyEager ) { delete params . $modifyEager ; }
163164 if ( params . $mergeEager ) { delete params . $mergeEager ; }
164165 if ( params . $noSelect ) { delete params . $noSelect ; }
165166 if ( params . $modify ) { delete params . $modify ; }
167+ if ( params . $allowRefs ) { delete params . $allowRefs ; }
166168
167169 Object . keys ( params || { } ) . forEach ( key => {
168170 let value = params [ key ] ;
169171
170172 if ( utils . isPlainObject ( value ) ) {
171- return this . objectify ( query , value , key , parentKey ) ;
173+ return this . objectify ( query , value , key , parentKey , allowRefs ) ;
172174 }
173175
174176 const column = parentKey && parentKey [ 0 ] !== '$' ? parentKey : key ;
@@ -182,7 +184,7 @@ class Service extends AdapterService {
182184 return query . where ( function ( ) {
183185 return value . forEach ( ( condition ) => {
184186 this . orWhere ( function ( ) {
185- self . objectify ( this , condition ) ;
187+ self . objectify ( this , condition , null , null , allowRefs ) ;
186188 } ) ;
187189 } ) ;
188190 } ) ;
@@ -194,7 +196,7 @@ class Service extends AdapterService {
194196 return query . where ( function ( ) {
195197 return value . forEach ( ( condition ) => {
196198 this . andWhere ( function ( ) {
197- self . objectify ( this , condition ) ;
199+ self . objectify ( this , condition , null , null , allowRefs ) ;
198200 } ) ;
199201 } ) ;
200202 } ) ;
@@ -212,7 +214,7 @@ class Service extends AdapterService {
212214 if ( columnType ) {
213215 if ( Array . isArray ( columnType ) ) { columnType = columnType [ 0 ] ; }
214216 if ( columnType === 'object' || columnType === 'array' ) {
215- let refColumn = null ;
217+ let refColumn ;
216218
217219 if ( ! methodKey && key [ 0 ] === '$' ) {
218220 refColumn = ref ( `${ this . Model . tableName } .${ column } ` ) ;
@@ -242,6 +244,12 @@ class Service extends AdapterService {
242244 value = JSON . parse ( value ) ;
243245 }
244246
247+ if ( allowRefs && typeof value === 'string' ) {
248+ const refMatches = value . match ( / ^ r e f \( ( .+ ) \) $ / ) ;
249+
250+ if ( refMatches ) { value = ref ( refMatches [ 1 ] ) ; }
251+ }
252+
245253 return operator === '=' ? query . where ( column , value ) : query . where ( column , operator , value ) ;
246254 } ) ;
247255 }
@@ -337,15 +345,15 @@ class Service extends AdapterService {
337345 const eagerFilterQuery = query . $modifyEager [ eagerFilterExpression ] ;
338346
339347 q . modifyGraph ( eagerFilterExpression , builder => {
340- this . objectify ( builder , eagerFilterQuery ) ;
348+ this . objectify ( builder , eagerFilterQuery , null , null , query . $allowRefs ) ;
341349 } ) ;
342350 }
343351
344352 delete query . $modifyEager ;
345353 }
346354
347355 // build up the knex query out of the query params
348- this . objectify ( q , query ) ;
356+ this . objectify ( q , query , null , null , query . $allowRefs ) ;
349357
350358 if ( filters . $sort ) {
351359 Object . keys ( filters . $sort ) . forEach ( item => {
@@ -414,7 +422,7 @@ class Service extends AdapterService {
414422 countQuery . count ( { total : idColumns } ) ;
415423 }
416424
417- this . objectify ( countQuery , query ) ;
425+ this . objectify ( countQuery , query , null , null , query . $allowRefs ) ;
418426
419427 return countQuery
420428 . then ( count => parseInt ( count [ 0 ] . total , 10 ) )
@@ -596,7 +604,7 @@ class Service extends AdapterService {
596604
597605 const q = this . _createQuery ( params ) ;
598606
599- this . objectify ( q , query ) ;
607+ this . objectify ( q , query , null , null , query . $allowRefs ) ;
600608
601609 if ( Array . isArray ( this . id ) ) {
602610 for ( const idKey of this . id ) {
@@ -661,7 +669,7 @@ class Service extends AdapterService {
661669 const { query : queryParams } = this . filterQuery ( params ) ;
662670 const query = this . _createQuery ( params ) ;
663671
664- this . objectify ( query , queryParams ) ;
672+ this . objectify ( query , queryParams , null , null , query . $allowRefs ) ;
665673
666674 if ( params . query && params . query . $noSelect ) {
667675 return query . delete ( ) . then ( ( ) => {
0 commit comments