Skip to content

Commit 2c3ffb9

Browse files
hendrysadrakdziraf
authored andcommitted
fix: Support defining field references by passing Model instance
1 parent bc465fc commit 2c3ffb9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/property.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ class Property extends BaseProperty {
7070
}
7171

7272
reference() {
73-
if (this.isArray()) {
74-
return this.mongoosePath.caster.options && this.mongoosePath.caster.options.ref
75-
}
76-
return this.mongoosePath.options && this.mongoosePath.options.ref
73+
const ref = this.isArray()
74+
? this.mongoosePath.caster.options?.ref
75+
: this.mongoosePath.options?.ref
76+
77+
if (typeof ref === 'function') return ref.modelName
78+
79+
return ref
7780
}
7881

7982
isVisible() {

0 commit comments

Comments
 (0)