This repository was archived by the owner on Apr 17, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,7 @@ class KnormRelations {
256
256
}
257
257
258
258
join . parent = this ;
259
+ // depended on by @knorm /postgres
259
260
join . config . joined = true ;
260
261
join . config . index = ++ this . config . index ;
261
262
// TODO: support custom aliases
@@ -327,18 +328,16 @@ class KnormRelations {
327
328
// values while parsing the row but at a cost of code complexity
328
329
const isEmpty = Object . values ( data ) . every ( value => value === null ) ;
329
330
330
- if ( first ) {
331
+ if ( isEmpty ) {
332
+ // TODO: test this next `if`
333
+ if ( ! parsedRow [ as ] ) {
334
+ parsedRow [ as ] = null ;
335
+ }
336
+ } else if ( first ) {
331
337
parsedRow [ as ] = data ;
332
338
} else {
333
- if ( isEmpty ) {
334
- // TODO: test this
335
- if ( ! parsedRow [ as ] ) {
336
- parsedRow [ as ] = null ;
337
- }
338
- } else {
339
- parsedRow [ as ] = parsedRow [ as ] || [ ] ;
340
- parsedRow [ as ] . push ( data ) ;
341
- }
339
+ parsedRow [ as ] = parsedRow [ as ] || [ ] ;
340
+ parsedRow [ as ] . push ( data ) ;
342
341
}
343
342
} ) ;
344
343
}
Original file line number Diff line number Diff line change @@ -644,6 +644,23 @@ describe('KnormRelations', () => {
644
644
[ new User ( { id : 1 , name : 'User 1' , image : new Image ( { id : 1 } ) } ) ]
645
645
) ;
646
646
} ) ;
647
+
648
+ // TODO: requires fixes in @knorm /postgres
649
+ it . skip ( 'includes other joined models as `null` if no rows were matched' , async ( ) => {
650
+ const query = new Query ( User ) . leftJoin ( new Query ( Image ) . first ( ) ) ;
651
+ await expect (
652
+ query . fetch ( ) ,
653
+ 'to be fulfilled with sorted rows satisfying' ,
654
+ [
655
+ new User ( {
656
+ id : 1 ,
657
+ name : 'User 1' ,
658
+ image : new Image ( { id : 1 } )
659
+ } ) ,
660
+ new User ( { id : 2 , name : 'User 2' , image : null } )
661
+ ]
662
+ ) ;
663
+ } ) ;
647
664
} ) ;
648
665
649
666
it ( 'creates a left join to the model on all fields wih references' , async ( ) => {
You can’t perform that action at this time.
0 commit comments