Hello, on my portfolio schema i have a field called Charities as it shows below:
What i want to achieve is to set that relation data required when creating a new portfolio. Is there any way to achieve this?
Hello, on my portfolio schema i have a field called Charities as it shows below:
What i want to achieve is to set that relation data required when creating a new portfolio. Is there any way to achieve this?
Hello @usr1vang,
In other words, you don’t want to be able to create a new record if charity_id
is null. You want charity_id
to be a required field. And here even though you have added required: true
it’s not the case.
Am I correct?
Best regards,
Mia
Hi, yes, that’s how you mentioned.
Hello @usr1vang,
I am gonna try to reproduce your error and see why it’s not working even though you added required: true
. Will get back to you as soon as possible.
Hello @usr1vang,
We are still investigating. I will give you more informations next week.
Regards,
Morgan
Hello @usr1vang,
I think I’ve spotted your problem. You have only made charity_id required.
Moreover, that are you trying to achieve ? If you try to do a HasMany relationship. You only need to write the following code in your mongoose model.
'charities': [{ type: Mongoose.Schema.Types.ObjectId, ref: 'charities' }],
You can find more informations about relationship here (look at mongoose examples).
Tell if it helps.
Regards,
Morgan