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

How can associate with multiple model? #39

Closed
samseralam opened this issue Aug 31, 2017 · 2 comments
Closed

How can associate with multiple model? #39

samseralam opened this issue Aug 31, 2017 · 2 comments

Comments

@samseralam
Copy link

samseralam commented Aug 31, 2017

Hi, @JKHeadley
I need to make association with multiple field, so is there any way to define association with more than one model?.
example:
my schema is like this:
masterField: [{

         abc: [{
             facility: {
                 type: Types.ObjectId,
                 ref: "abc"
             }
         }],
         xyz: [{
             item: {
                 type: Types.ObjectId,
                 ref: "xyz"
             }
     }]

}]

associations: {
type:.............?
model:...........?

}

How can i associate abc and xyz model with masterField so that i can embed masterField to populate abc and xyz ?

@samseralam samseralam changed the title How can associate with multiple field? How can associate with multiple model? Aug 31, 2017
@JKHeadley
Copy link
Owner

I don't believe what you are trying to do will work with the regular $embed query. However you might be able to accomplish this with a solution similar to the one posted in #31.

If this turns out to be too much trouble, it would probably be easier to split up/add more models (and associate them) rather than trying to encapsulate all the relationships into one field.

@samseralam
Copy link
Author

samseralam commented Sep 1, 2017

Thanks @JKHeadley
Absolutely! split up/add more models

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