@@ -586,38 +586,38 @@ Join related records.
586
586
const { fastJoin } = require (' feathers-hooks-common' );
587
587
588
588
const postResolvers = {
589
- joins: {
590
- author : (... args ) => async post => post .author = (await users .find ({
591
- query: { id: post .userId },
592
- paginate: false
593
- }))[0 ],
589
+ joins: {
590
+ author : (... args ) => async post => post .author = (await users .find ({
591
+ query: { id: post .userId },
592
+ paginate: false
593
+ }))[0 ],
594
594
595
- starers : $select => async post => post .starers = await users .find ({
595
+ starers : $select => async post => post .starers = await users .find ({
596
596
query: { id: { $in: post .starIds }, $select: $select || [' name' ] },
597
- paginate: false
598
- }),
599
- }
597
+ paginate: false
598
+ }),
599
+ }
600
600
};
601
601
602
602
const query = {
603
- author: true ,
604
- starers: [[' id' , ' name' ]]
603
+ author: true ,
604
+ starers: [[' id' , ' name' ]]
605
605
};
606
606
607
607
module .exports = { after: {
608
- all: [ fastJoin (postResolvers, query) ],
608
+ all: [ fastJoin (postResolvers, query) ],
609
609
} };
610
610
611
611
// Original record
612
612
[ { id: 1 , body: ' John post' , userId: 101 , starIds: [102 , 103 , 104 ] } ]
613
613
614
614
// Result
615
615
[ { id: 1 ,
616
- body: ' John post' ,
617
- userId: 101 ,
618
- starIds: [ 102 , 103 , 104 ],
619
- author: { id: 101 , name: ' John' },
620
- starers: [ { name: ' Marshall' }, { name: ' Barbara' }, { name: ' Aubree' } ]
616
+ body: ' John post' ,
617
+ userId: 101 ,
618
+ starIds: [ 102 , 103 , 104 ],
619
+ author: { id: 101 , name: ' John' },
620
+ starers: [ { name: ' Marshall' }, { name: ' Barbara' }, { name: ' Aubree' } ]
621
621
}]
622
622
623
623
` ` `
0 commit comments