@@ -232,29 +232,35 @@ module.exports =
232232 } ) ( ) ;
233233 } else if ( def . type === 'belongsTo' || def . type === 'hasOne' && def . localKey ) {
234234 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+ }
239242 } 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
246252 } )
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+ } ) ;
254260 } ) ;
261+ return relatedItems ;
255262 } ) ;
256- return relatedItems ;
257- } ) ;
263+ }
258264 }
259265 }
260266
@@ -503,6 +509,8 @@ module.exports =
503509 }
504510 } else if ( op === 'like' ) {
505511 query = query . where ( field , 'like' , v ) ;
512+ } else if ( op === '|like' ) {
513+ query = query . orWhere ( field , 'like' , v ) ;
506514 } else if ( op === '|==' || op === '|===' ) {
507515 if ( v === null ) {
508516 query = query . orWhereNull ( field ) ;
0 commit comments