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

Mongoose new Model() #11

Closed
musanek opened this issue Apr 15, 2014 · 9 comments
Closed

Mongoose new Model() #11

musanek opened this issue Apr 15, 2014 · 9 comments

Comments

@musanek
Copy link

musanek commented Apr 15, 2014

I am aware new Mongoose externs are still hot :), but maybe this is a simple fix. I am not able to create a Document out of a model with just calling the constructor. (not using create)

var stuff = new Stuff(); //non persisted doc

Thanks for your work!

@musanek
Copy link
Author

musanek commented Apr 15, 2014

After some digging I end up doing

var stuff = StuffManager.build(db,"Stuff");
var s : Stuff = untyped stuff();

Seems to me that the mongoose oop model is somewhat messy.

clemos added a commit that referenced this issue Apr 16, 2014
@clemos
Copy link
Owner

clemos commented Apr 16, 2014

Yeah, the externs are still hot :)
I've changed the signature of Document::new so that you should be able to do :

var s : Stuff = new Stuff({ foo : "bar" });
s.save(...);

There still seem to be some issues, though (trying to trace(s) for instance)...

@musanek
Copy link
Author

musanek commented Apr 16, 2014

The parameters not being optional is not the issue, the issue is that the Document (super) constructor is not being called as it is missing in js.npm.macro.Model. I would put it there myself, but the problem is it does not work anyway, because you have to call the constructor on which moongoose.model() returns, which is Manager.

@clemos
Copy link
Owner

clemos commented Apr 16, 2014

Yeah, right...
Mongoose's OOP model is broken indeed...
I'll think about a better solution (probably a helper method...)

@clemos
Copy link
Owner

clemos commented Apr 16, 2014

maybe stuff.construct(?doc) return untyped this(doc)
I hate so much having to do that... :\

@clemos
Copy link
Owner

clemos commented Apr 16, 2014

or _new...

@musanek
Copy link
Author

musanek commented Apr 16, 2014

I vote for construct ;). Thank a lot

@clemos
Copy link
Owner

clemos commented Apr 16, 2014

construct it is...
I updated it, feel free to close this issue.
Thanks for reporting :)

@musanek
Copy link
Author

musanek commented Apr 16, 2014

Thanks!

@musanek musanek closed this as completed Apr 16, 2014
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