SoftwareBrothers / adminjs-mongoose

Mongoose adapter for AdminJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling `ref`

hendrysadrak opened this issue · comments

reference() {
const ref = this.isArray()
? this.mongoosePath.caster.options?.ref
: this.mongoosePath.options?.ref
if (typeof ref === 'function') return ref.modelName
return ref
}

This part requires another update because the ref in mongoose can be defined as string | Model<any> | ((this: any, doc: any) => string | Model<any>);

image

Right now this logic correctly handles ref: string | Model but not the ref: () => string | Model part

Line 77 should be updated to

if (typeof ref === 'function') return ref.modelName || ref().modelName

Lmk what you think