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

Saving an id to a custom column fails #46

Closed
naturalethic opened this issue Sep 3, 2010 · 9 comments
Closed

Saving an id to a custom column fails #46

naturalethic opened this issue Sep 3, 2010 · 9 comments

Comments

@naturalethic
Copy link

I have a model with a field called '_account', which should default to a type of ObjectID. When I create a new instance and try to set '_account' to the '_id' of another object, it applies correctly to the object, but when I save the object, that field '_account' remains blank, and the type is reported as String.

@nw
Copy link
Contributor

nw commented Sep 3, 2010

have you tried defining a cast for that particular property?

casts: { account: ObjectID }

above your model you will need to define ObjectID. You should be able to do the following.

var ObjectID = require('mongodb').ObjectID

if you want the casting to be automatic you can just add an underscore to the name, and mongoose will handle the rest.

@naturalethic
Copy link
Author

I did try a cast how you suggested, but that also didn't work, and I use an underscore at the beginning of the field name. Keep in mind, the property is getting set on the object as I can see by inspecting the object before and after save, however when I view the object in the database, or load the object back up, that property is unset.

@nw
Copy link
Contributor

nw commented Sep 3, 2010

and that particular property is defined in your properties: [] ?

for sanity checking you can inspect doc.__doc to see if the property is actually in the internal doc that gets saved down.

@naturalethic
Copy link
Author

Yes it is present in my properties array. It is present in the __doc. It is also marked as dirty. Every other field saves properly. If I inspect after I save, it is also still there. However, if I load it back up, or inspect it with MongoHub, it is empty.

@nw
Copy link
Contributor

nw commented Sep 3, 2010

any other information you can provide would be great. Like what version of mongodb your connecting too. I have not seen this issue, I'll try and reproduce later.

@naturalethic
Copy link
Author

I'm using edge version of MongoDB.

@nw
Copy link
Contributor

nw commented Sep 3, 2010

do you know what version of mongodb-native your using? It should be locked in at v0.7.9.

check out my comment on http://github.com/LearnBoost/mongoose/issues#issue/47 for reasons why.

@naturalethic
Copy link
Author

Ug. MongoHub is the culprit. It doesn't display ObjectID's other than _id apparently. I had thought I had tested without MongoHub but I must not have. Sorry to waste your time on this.

@nw
Copy link
Contributor

nw commented Oct 13, 2010

resolved

This issue was closed.
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