Skip to content

Commit 90d3c65

Browse files
authored
perf: automatically add index on a relationship field when used as target for a join field (#11463)
When the join field is used, Payload now automatically adds an index on the target relationship field. For example: ``` { name: 'relatedPosts', type: 'join', collection: "posts", on: 'category', }, { name: 'category', type: 'relationship', relationTo: "categories", }, ``` Here, `index: true` implicitly added to the `category` relationship field during sanitization to improve querying performance.
1 parent e75d38c commit 90d3c65

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/payload/src/fields/config/sanitizeJoinField.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export const sanitizeJoinField = ({
139139
throw new InvalidFieldJoin(join.field)
140140
}
141141

142+
if (!joinRelationship.index && !joinRelationship.unique) {
143+
joinRelationship.index = true
144+
}
145+
142146
if (validateOnly) {
143147
return
144148
}

0 commit comments

Comments
 (0)