Open Pyo25 opened 8 years ago
Where you select: 'Email'
change to select: 'Email Username'
. I think what is happening is the foreignKey field isn't being returned because it's not selected. Just a guess... the code looks correct otherwise.
Indeed, it helped to add the Username
in the select: when debugging, I can see that the final promise is resolved with an object correctly populated. (in the Model.populate
method)
However in my main script the attribute is still undefined. It's like the property was overridden afterwards.
Do you have any idea what I could investigate?
Btw I'm using Mongoose 4.4.3 (+ MongoDB driver 2.1.7). On which version did you test?
I realized the property was deleted in the init
pre middleware line 35 and the virtual getter is not called when I access the attribute. This is why I got an undefined. If I remove the delete line, then I can access the populated field.
I don't really understand why the getter is not called... Any idea?
"select" must include "foreignKey".
this case {select: 'Email'} change to {select: 'Email Username'}
Can add auto append foreignKey as _id?
Hello,
I'm trying to use the plugin because I'm using an existing dataset that doesn't follow Mongoose conventions. Typically, I have this kind of models:
I'd like to use Mongoose to get a task and populate it with the corresponding user using the 'Username' as a key. I tried to use the plugin but the virtual field stays undefined.
Here is the code I wrote to test:
The output is:
Moreover if I try to "debug" the plugin, I can see that the user is correctly loaded. In the
assignVals
method, I can output the different parameters and there is thisundefined
key that looks strange:Am I doing something wrong or is there something broken?
Thank you!