@@ -232,29 +232,35 @@ module.exports =
232
232
} ) ( ) ;
233
233
} else if ( def . type === 'belongsTo' || def . type === 'hasOne' && def . localKey ) {
234
234
if ( instance ) {
235
- task = _this . find ( resourceConfig . getResource ( relationName ) , DSUtils . get ( instance , def . localKey ) , __options ) . then ( function ( relatedItem ) {
236
- instance [ def . localField ] = relatedItem ;
237
- return relatedItem ;
238
- } ) ;
235
+ var id = DSUtils . get ( instance , def . localKey ) ;
236
+ if ( id ) {
237
+ task = _this . find ( resourceConfig . getResource ( relationName ) , DSUtils . get ( instance , def . localKey ) , __options ) . then ( function ( relatedItem ) {
238
+ instance [ def . localField ] = relatedItem ;
239
+ return relatedItem ;
240
+ } ) ;
241
+ }
239
242
} else {
240
- task = _this . findAll ( resourceConfig . getResource ( relationName ) , {
241
- where : _defineProperty ( { } , relationDef . idAttribute , {
242
- 'in' : DSUtils . filter ( items . map ( function ( item ) {
243
- return DSUtils . get ( item , def . localKey ) ;
244
- } ) , function ( x ) {
245
- return x ;
243
+ var ids = DSUtils . filter ( items . map ( function ( item ) {
244
+ return DSUtils . get ( item , def . localKey ) ;
245
+ } ) , function ( x ) {
246
+ return x ;
247
+ } ) ;
248
+ if ( ids . length ) {
249
+ task = _this . findAll ( resourceConfig . getResource ( relationName ) , {
250
+ where : _defineProperty ( { } , relationDef . idAttribute , {
251
+ 'in' : ids
246
252
} )
247
- } )
248
- } , __options ) . then ( function ( relatedItems ) {
249
- DSUtils . forEach ( items , function ( item ) {
250
- DSUtils . forEach ( relatedItems , function ( relatedItem ) {
251
- if ( relatedItem [ relationDef . idAttribute ] === item [ def . localKey ] ) {
252
- item [ def . localField ] = relatedItem ;
253
- }
253
+ } , __options ) . then ( function ( relatedItems ) {
254
+ DSUtils . forEach ( items , function ( item ) {
255
+ DSUtils . forEach ( relatedItems , function ( relatedItem ) {
256
+ if ( relatedItem [ relationDef . idAttribute ] === item [ def . localKey ] ) {
257
+ item [ def . localField ] = relatedItem ;
258
+ }
259
+ } ) ;
254
260
} ) ;
261
+ return relatedItems ;
255
262
} ) ;
256
- return relatedItems ;
257
- } ) ;
263
+ }
258
264
}
259
265
}
260
266
@@ -503,6 +509,8 @@ module.exports =
503
509
}
504
510
} else if ( op === 'like' ) {
505
511
query = query . where ( field , 'like' , v ) ;
512
+ } else if ( op === '|like' ) {
513
+ query = query . orWhere ( field , 'like' , v ) ;
506
514
} else if ( op === '|==' || op === '|===' ) {
507
515
if ( v === null ) {
508
516
query = query . orWhereNull ( field ) ;
0 commit comments