{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/859","labels_url":"https://api.github.com/repos/balderdashy/waterline/issues/859/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/waterline/issues/859/comments","events_url":"https://api.github.com/repos/balderdashy/waterline/issues/859/events","html_url":"https://github.com/balderdashy/waterline/issues/859","id":58957752,"number":859,"title":"Using more than 2 populates fails due to a \"bug\" in the code","user":{"login":"tyrghen","id":8298371,"avatar_url":"https://avatars.githubusercontent.com/u/8298371?v=3","gravatar_id":"","url":"https://api.github.com/users/tyrghen","html_url":"https://github.com/tyrghen","followers_url":"https://api.github.com/users/tyrghen/followers","following_url":"https://api.github.com/users/tyrghen/following{/other_user}","gists_url":"https://api.github.com/users/tyrghen/gists{/gist_id}","starred_url":"https://api.github.com/users/tyrghen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tyrghen/subscriptions","organizations_url":"https://api.github.com/users/tyrghen/orgs","repos_url":"https://api.github.com/users/tyrghen/repos","events_url":"https://api.github.com/users/tyrghen/events{/privacy}","received_events_url":"https://api.github.com/users/tyrghen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-25T19:40:39Z","updated_at":"2015-02-26T07:43:02Z","closed_at":"2015-02-26T07:43:02Z","body":"Using the last versions of sails-postgresql and waterline gave me an error at the \"waterline-sequel\" level in the sails-postgresql adapter for a query with more than 2 populates.\r\n```javascript\r\nUsers.find({...}).populate('addresses').populate('contracts').populate('notes')\r\n```\r\n\r\nThe error is \"TypeError: Cannot convert null to object\" and originates from:\r\n```javascript\r\nif(!hop(population.criteria, 'sort')) {\r\n```\r\n\r\nhttps://github.com/balderdashy/waterline-sequel/blob/master/sequel/where.js#L214\r\nThe reason is that the population.criteria of the third (and further) populate is \"undefined\".\r\n\r\nWhat it was hiding, is that well above in the code chain, the Waterline deferred method does the following:\r\n```javascript\r\nif(criteria && joins.length > 1) {\r\n  joins[1].criteria = criteria;\r\n} else if(criteria) {\r\n   joins[0].criteria = criteria;\r\n}\r\n```\r\nhttps://github.com/balderdashy/waterline/blob/master/lib/waterline/query/deferred.js#L268\r\n\r\nSince, in our case, we have 3 or more joins, no more than the two first will get populated and we'll just overwrite the second join criteria each time.\r\n\r\nI hope my explanation is clear enough."},"comment":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/comments/76135054","html_url":"https://github.com/balderdashy/waterline/issues/859#issuecomment-76135054","issue_url":"https://api.github.com/repos/balderdashy/waterline/issues/859","id":76135054,"user":{"login":"tyrghen","id":8298371,"avatar_url":"https://avatars.githubusercontent.com/u/8298371?v=3","gravatar_id":"","url":"https://api.github.com/users/tyrghen","html_url":"https://github.com/tyrghen","followers_url":"https://api.github.com/users/tyrghen/followers","following_url":"https://api.github.com/users/tyrghen/following{/other_user}","gists_url":"https://api.github.com/users/tyrghen/gists{/gist_id}","starred_url":"https://api.github.com/users/tyrghen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tyrghen/subscriptions","organizations_url":"https://api.github.com/users/tyrghen/orgs","repos_url":"https://api.github.com/users/tyrghen/repos","events_url":"https://api.github.com/users/tyrghen/events{/privacy}","received_events_url":"https://api.github.com/users/tyrghen/received_events","type":"User","site_admin":false},"created_at":"2015-02-26T07:43:02Z","updated_at":"2015-02-26T07:43:02Z","body":"Scrap that, found a bad dependency on the git code.\r\nNow the code works as expected.\r\n\r\nThere was still an old version of waterline being installed."}}