-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Is it possible to create a record without assigning a PK & saving? #5840
Comments
I'd also like to do this; is this possible? if so could you document it? |
This should work: |
Using an underscored method is a code smell. Can we have this as a public API, please? |
Sure mind putting together a pull request? |
Yup I'll get to this later tonight Sent from my T-Mobile 4G LTE Device -------- Original message -------- From: Cody Stoltman notifications@github.com Date:01/16/2015 12:17 PM (GMT-06:00) To: balderdashy/waterline waterline@noreply.github.com Cc: Ruben Rodriguez cha0s@therealcha0s.net Subject: Re: [waterline] Is it possible to create a record without assigning a
PK & saving? (#763) — |
Do you have a preference about the syntax? In the project I desired this functionality in, I augmented all collections with Does that seem like a good name? Should we go with Might as well talk about it a little before I bother with a PR :) |
+1 for this. I wouldn't mind helping out with a PR as waterline has saved me a ton of development and maintenance time. My use case is creating multiple instances of a model, but only if they are all valid. |
Was any method to support this feature added? |
No, there wasn't, but I would love to see a PR for this! Using |
Some example code: var user = User._model({ email: 'foo@bar.com' });
user.save()
.then(function() {
console.log(user.id);
})
.catch(function(err) {
console.log(err);
}); Is there another workaround I can use for now? Otherwise are there any plans to make a method providing this functionality available through a public api? I'd be willing to submit a pull request that implements that if it's wanted. There's an existing package called |
Ah, correct– |
I have a similar problem:
this method does not return a good model, for example it does not convert Help, please! |
sails-mongo has a utility method to normalize results based upon a schema: https://github.com/balderdashy/sails-mongo/blob/master/lib/utils.js#L78-L96 |
Unfortunately it doesn't in this case. I'm trying to build an adapter between waterline and factory girl and part of the interface is the ability to build a record without saving it and then subsequently save it later on. I hacked around it myself for now but would be nice to fix the underlying issue so I can build the adapter into a real node package and release it. I'll try to submit a pull request that fixes this since it seems like you're open to it. |
I am open to it– not sure where @particlebanana and others are with this. But at least in the next big waterline release, I would love to see a proper public API for creating model instances. |
@devinivy +10000547 |
Yeah having |
I think I like the former solution of |
I'd like to be able to create an instance of a model without actually saving it or generating a PK (ID would equal null). Is this possible? I'd like to get an instance with all defaults populated, etc. but not actually save it.
The text was updated successfully, but these errors were encountered: