{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/940","labels_url":"https://api.github.com/repos/balderdashy/waterline/issues/940/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/waterline/issues/940/comments","events_url":"https://api.github.com/repos/balderdashy/waterline/issues/940/events","html_url":"https://github.com/balderdashy/waterline/pull/940","id":67190764,"number":940,"title":"FindAndModify + upsert","user":{"login":"Globegitter","id":2580254,"avatar_url":"https://avatars.githubusercontent.com/u/2580254?v=3","gravatar_id":"","url":"https://api.github.com/users/Globegitter","html_url":"https://github.com/Globegitter","followers_url":"https://api.github.com/users/Globegitter/followers","following_url":"https://api.github.com/users/Globegitter/following{/other_user}","gists_url":"https://api.github.com/users/Globegitter/gists{/gist_id}","starred_url":"https://api.github.com/users/Globegitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Globegitter/subscriptions","organizations_url":"https://api.github.com/users/Globegitter/orgs","repos_url":"https://api.github.com/users/Globegitter/repos","events_url":"https://api.github.com/users/Globegitter/events{/privacy}","received_events_url":"https://api.github.com/users/Globegitter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"particlebanana","id":370260,"avatar_url":"https://avatars.githubusercontent.com/u/370260?v=3","gravatar_id":"","url":"https://api.github.com/users/particlebanana","html_url":"https://github.com/particlebanana","followers_url":"https://api.github.com/users/particlebanana/followers","following_url":"https://api.github.com/users/particlebanana/following{/other_user}","gists_url":"https://api.github.com/users/particlebanana/gists{/gist_id}","starred_url":"https://api.github.com/users/particlebanana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/particlebanana/subscriptions","organizations_url":"https://api.github.com/users/particlebanana/orgs","repos_url":"https://api.github.com/users/particlebanana/repos","events_url":"https://api.github.com/users/particlebanana/events{/privacy}","received_events_url":"https://api.github.com/users/particlebanana/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/balderdashy/waterline/milestones/8","html_url":"https://github.com/balderdashy/waterline/milestones/0.11","labels_url":"https://api.github.com/repos/balderdashy/waterline/milestones/8/labels","id":765772,"number":8,"title":"0.11","description":"Date tentatively set to July 3rd (roughly a year after v0.10).","creator":{"login":"tjwebb","id":1009114,"avatar_url":"https://avatars.githubusercontent.com/u/1009114?v=3","gravatar_id":"","url":"https://api.github.com/users/tjwebb","html_url":"https://github.com/tjwebb","followers_url":"https://api.github.com/users/tjwebb/followers","following_url":"https://api.github.com/users/tjwebb/following{/other_user}","gists_url":"https://api.github.com/users/tjwebb/gists{/gist_id}","starred_url":"https://api.github.com/users/tjwebb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjwebb/subscriptions","organizations_url":"https://api.github.com/users/tjwebb/orgs","repos_url":"https://api.github.com/users/tjwebb/repos","events_url":"https://api.github.com/users/tjwebb/events{/privacy}","received_events_url":"https://api.github.com/users/tjwebb/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":7,"state":"open","created_at":"2014-08-26T09:01:15Z","updated_at":"2015-05-13T19:00:55Z","due_on":"2015-07-02T23:00:00Z","closed_at":null},"comments":11,"created_at":"2015-04-08T18:32:24Z","updated_at":"2015-05-21T00:11:45Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/balderdashy/waterline/pulls/940","html_url":"https://github.com/balderdashy/waterline/pull/940","diff_url":"https://github.com/balderdashy/waterline/pull/940.diff","patch_url":"https://github.com/balderdashy/waterline/pull/940.patch"},"body":"As mentioned by @dmarcelino in https://github.com/balderdashy/waterline/pull/939 a PR against the `0.11` branch.\r\n\r\nI know there is the current discussion going on about `findOrCreateEach` (\r\nhttps://github.com/balderdashy/waterline/issues/931) so it might not have been the wisest choice to add a `findAndModifyEach` but I needed a `findAndModify` 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.\r\n\r\nUsage is `Model.findAndModify(search critieras, values, [options, cb]);`\r\n\r\nwhere-as default options look like that:\r\n\r\n```js\r\n{\r\n  upsert: false, // on true automatically inserts the values if nothing is found\r\n  new: true, // if false returns the model before it was updated/created\r\n  mergeArrays: false // quite a special case that I needed and I am still testing in my app. When any of the values given contain an array it is merged to the found object rather than just replaced.\r\n}\r\n```\r\n\r\nI added passing unit tests as well as adapter-tests, see https://github.com/balderdashy/waterline-adapter-tests/pull/47\r\nThere is something strange going on, even though the `findAndModify` passes the unit tests and works  in my app (via `npm i git+https://github.com/Globegitter/waterline.git#findAndModify`) the adapter-tests do not pass and throw the same error throughout:\r\n\r\n```js\r\n9) Semantic Interface .findAndModfiy() should return a model instance:\r\n     TypeError: undefined is not a function\r\n      at Context.<anonymous> (Git/waterline/node_modules/waterline-adapter-tests/interfaces/semantic/findAndModify.test.js:73:20)\r\n      at Test.Runnable.run (Git/waterline/node_modules/waterline-adapter-tests/node_modules/mocha/lib/runnable.js:194:15)\r\n      at Runner.runTest (Git/waterline/node_modules/waterline-adapter-tests/node_modules/mocha/lib/runner.js:355:10)\r\n      at Git/waterline/node_modules/waterline-adapter-tests/node_modules/mocha/lib/runner.js:401:12\r\n      at next (Git/waterline/node_modules/waterline-adapter-tests/node_modules/mocha/lib/runner.js:281:14)\r\n      at Git/waterline/node_modules/waterline-adapter-tests/node_modules/mocha/lib/runner.js:290:7\r\n      at next (Git/waterline/node_modules/waterline-adapter-tests/node_modules/mocha/lib/runner.js:234:23)\r\n      at Immediate._onImmediate (Git/waterline/node_modules/waterline-adapter-tests/node_modules/mocha/lib/runner.js:258:5)\r\n      at processImmediate [as _immediateCallback] (timers.js:361:17)\r\n```\r\n\r\nI 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?\r\n\r\nAlso 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 to `sails-postgresql`.\r\n\r\n```\r\ndb_1     | ERROR:  syntax error at or near \"LIMIT\" at character 140\r\ndb_1     | STATEMENT:  UPDATE \"subject\" AS \"subject\" SET \"researchIds\" = $1, \"text\" = $2, \"createdAt\" = $3, \"updatedAt\" = $4  WHERE LOWER(\"subject\".\"text\") = $5  LIMIT 1 RETURNING *\r\n````"},"comment":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/comments/104076855","html_url":"https://github.com/balderdashy/waterline/pull/940#issuecomment-104076855","issue_url":"https://api.github.com/repos/balderdashy/waterline/issues/940","id":104076855,"user":{"login":"dmarcelino","id":1280446,"avatar_url":"https://avatars.githubusercontent.com/u/1280446?v=3","gravatar_id":"","url":"https://api.github.com/users/dmarcelino","html_url":"https://github.com/dmarcelino","followers_url":"https://api.github.com/users/dmarcelino/followers","following_url":"https://api.github.com/users/dmarcelino/following{/other_user}","gists_url":"https://api.github.com/users/dmarcelino/gists{/gist_id}","starred_url":"https://api.github.com/users/dmarcelino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmarcelino/subscriptions","organizations_url":"https://api.github.com/users/dmarcelino/orgs","repos_url":"https://api.github.com/users/dmarcelino/repos","events_url":"https://api.github.com/users/dmarcelino/events{/privacy}","received_events_url":"https://api.github.com/users/dmarcelino/received_events","type":"User","site_admin":false},"created_at":"2015-05-21T00:11:45Z","updated_at":"2015-05-21T00:11:45Z","body":"For reference, this will fix #790."}}