Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two way references not possible #41

Open
abdatta opened this issue Dec 20, 2019 · 1 comment
Open

Two way references not possible #41

abdatta opened this issue Dec 20, 2019 · 1 comment

Comments

@abdatta
Copy link

abdatta commented Dec 20, 2019

Right now we cannot create two schemas that both have references to each other. This is a variant of the issue #35.
I need to have two schemas, one for an Organization and one for a Member. So the code I wrote is this:

const OrganizationSchema = createSchema({
    name: Type.string({ required: true }),
    members: Type.array({default: []}).of(Type.ref(Type.objectId()).to('Member', MemberSchema))
});
const MemberSchema = createSchema({
    _id: Type.string({required: true, unique: true, index: true}),
    email: Type.string(),
    organization: Type.ref(Type.objectId()).to('Organization', OrganizationSchema)
});

The MemberSchema used in the definition of OrganizationSchema does not get recognized by typescript as it is not yet defined at that point.

Trying something like the workaround in issue #35 causes an issue in populateTs() where the populated items don't have the added properties. Also, I highly dislike the redundant type of code used for this workaround.

It would be great if you can fix this issue! Thanks!

@edshen17
Copy link

edshen17 commented Jul 16, 2021

Did you find a better workaround, or is the workaround in #35 the only way to go? One problem I have been facing is circular dependencies since if I split the schemas out into 2 different files the imports get messed up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants