-
Notifications
You must be signed in to change notification settings - Fork 45
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
When saving a model with an embedded document array of a base type, any fields present only in the derived types do not get saved #25
Comments
We're hitting the same issue. |
Hi there. I'm facing the same issue. I would like polymorphism inside an array. |
+1 |
Have you tried this with the discriminatorKey option also? Can't seem to get mine to save the discriminatorKey. Will have to implement it manually if this doesn't work |
+1 |
+1 We also need to have polymorphism within an array of subdocuments. When I use the base schema as the type in the array definition, none of the fields in the extended schemas are saved. When I use a mixed schema type, the _type discriminator key does not get saved. |
+1 |
1 similar comment
+1 |
Has someone already found a solution ??? |
I will check it, if anyone have solved it, please, let me know |
@sieira Any progress on this? |
Going off of the example currently in the readme, let's say you have a base
PersonSchema
, and a derivedEmployeeSchema
which adds thedepartment
field:Now let's add a third schema into the mix which has a field
people
that holds an array of embedded documents of typePersonSchema
:Let's create a contact list and add some people in it - in this example, they're both employees:
If you examine the database now, you'll notice that the
department
field did not get saved for either person - only thename
was saved:I'm not sure exactly why it's happening - I thought it might be because Mongoose is stripping out any fields that aren't part of the
PersonSchema
due to thestrict
option (enabled by default), but disabling it didn't seem to have any effect. The only workaround I've found is to use the Mixed schema type when definingContactListSchema
:With this change, the
department
field gets saved properly.Here's a complete test file that combines all the above snippets and also adds some expectations:
This requires the following:
Let me know if this behavior is by design, or if there is something else I'm supposed to do to use this library correctly.
I've tried this with mongoose v3.8.8, and mongoose-schema-extend v0.1.7.
The text was updated successfully, but these errors were encountered: