-
Notifications
You must be signed in to change notification settings - Fork 604
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
FindAndModify + upsert #940
Conversation
@dmarcelino Just seeing this now has all the commits that are missing on this branch - hope that's not an issue. In any case, any idea on what the issues mentioned above could be? |
We branched 0.11 some time ago and didn't keep it in sync with master, don't worry. No, nothing comes to mind... |
Allow objects that implement toDate to be cast
|
@anasyb Right now it really is the most basic implementation it could be (and that is actually all I need for my use-case). It just iterates through all the properties in the returned results, checks if the according element is an array. If it is it checks if it exists in the given values and if it is an array as well. If not it ignores it and if it is, it just concatenates these two and updates the found record with the new array (and everything else you originally gave it) If the find returns multiple results it just concatenates all of them to one array and will update all the results with that one 'big' array. I am mostly assuming here that you are trying to find uniquely indexed elements. Also now just writing about it makes me realise that I can optimise that implementation - thanks :) And yeah up for any improvements in any way ;) Also my use case is, I am querying an external API and generally keeping track of their ids. For |
Thanks for actually getting me to think about it a bit more @anasyb ;) Now it is looping over the given |
If anyone needs this functionality it has now been tested (with postgresql) in my running app and once #942 is merged should work using any of the adapters. |
Make shallow copy of criteria array for findOne
Ok something with rebasing to latest master seemed to go a bit wrong, but should all be looking good now and working if anyone needs it. |
Maybe I'm being pedantic, but we're introducing a new term to the waterline lingo: |
The only distinction I can find is the @Globegitter how do you justify the |
@tjwebb @devinivy The idea behind this query was to get http://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/, which they have in addition to their But my biggest reason to create this function was to add support for @devinivy In regards to the And yes I was thinking about the possibility to merge |
For reference, this will fix #790. |
I'm working on something today that could really use PS: we are getting closer to wrapping up 0.10, so hopefully we'll be able to care of this soon! |
+1 Would love to have |
Any news on this? |
+1 on upsert |
+1 on upsert. Will this be added to a released version? |
+1 on upsert |
Ok I get the I'm not sure I understand how |
@particlebanana findAndModify is not that different from a Waterline update, since the update in Waterline returns the updated models. Traditional SQL updates in for instance SQL Server does not return the updated records. |
closed w/o comment? @particlebanana did you get bitten by @sailsbot ? |
As mentioned by @dmarcelino in #939 a PR against the
0.11
branch.I know there is the current discussion going on about
findOrCreateEach
(https://github.com/balderdashy/waterline/issues/931) so it might not have been the wisest choice to add a
findAndModifyEach
but I needed afindAndModify
functionality (see http://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/) and it seemed like a good solution to put it such a way that other people can use it as well.Usage is
Model.findAndModify(search critieras, values, [options, cb]);
where-as default options look like that:
I added passing unit tests as well as adapter-tests, see balderdashy/waterline-adapter-tests#47
There is something strange going on, even though the
findAndModify
passes the unit tests and works in my app (vianpm i git+https://github.com/Globegitter/waterline.git#findAndModify
) the adapter-tests do not pass and throw the same error throughout:I have no idea why this happens or how to fix this. So apart from if this actually gets merged, anyone got any idea of why that could be?
Also it does not work completely in my app via
sails-postgresql
, I seem to be getting this error. I am not sure if that is related to my code or tosails-postgresql
.