Skip to content

Commit 0c76dab

Browse files
committed
deduplicate code
1 parent 0efee4d commit 0c76dab

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/db-mongodb/src/utilities/buildVirtualFieldsAggregation.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ export const buildVirtualFieldsAggregation = ({
3737
}
3838

3939
if ('virtual' in field && field.virtual && typeof field.virtual === 'object') {
40+
const relationshipPath = versions
41+
? `version.${field.virtual.relationship}`
42+
: field.virtual.relationship
4043
const currentPath = `${prefix}${field.name}`
4144
const relationshipField = getFieldByPath({
4245
fields: rootFields,
43-
path: versions ? `version.${field.virtual.relationship}` : field.virtual.relationship,
46+
path: relationshipPath,
4447
})
4548

4649
if (!relationshipField) {
@@ -81,9 +84,7 @@ export const buildVirtualFieldsAggregation = ({
8184
as: currentPath,
8285
foreignField: '_id',
8386
from: RelationshipModel.collection.name,
84-
localField: versions
85-
? `version.${field.virtual.relationship}`
86-
: field.virtual.relationship,
87+
localField: relationshipPath,
8788
pipeline: [
8889
{
8990
$project: {

0 commit comments

Comments
 (0)