{"action":"created","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/7252","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/7252/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/7252/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/7252/events","html_url":"https://github.com/cakephp/cakephp/issues/7252","id":101735036,"number":7252,"title":"ORM: Unexpected behavior with 'WHERE  IN' and array only has one element. ","user":{"login":"glkaup","id":4357199,"avatar_url":"https://avatars.githubusercontent.com/u/4357199?v=3","gravatar_id":"","url":"https://api.github.com/users/glkaup","html_url":"https://github.com/glkaup","followers_url":"https://api.github.com/users/glkaup/followers","following_url":"https://api.github.com/users/glkaup/following{/other_user}","gists_url":"https://api.github.com/users/glkaup/gists{/gist_id}","starred_url":"https://api.github.com/users/glkaup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glkaup/subscriptions","organizations_url":"https://api.github.com/users/glkaup/orgs","repos_url":"https://api.github.com/users/glkaup/repos","events_url":"https://api.github.com/users/glkaup/events{/privacy}","received_events_url":"https://api.github.com/users/glkaup/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cakephp/cakephp/labels/ORM","name":"ORM","color":"ffffff"},{"url":"https://api.github.com/repos/cakephp/cakephp/labels/Question","name":"Question","color":"207de5"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/cakephp/cakephp/milestones/55","html_url":"https://github.com/cakephp/cakephp/milestones/3.0.12","labels_url":"https://api.github.com/repos/cakephp/cakephp/milestones/55/labels","id":1243170,"number":55,"title":"3.0.12","description":"Bugfixes and enhancements for 3.0.x","creator":{"login":"markstory","id":24086,"avatar_url":"https://avatars.githubusercontent.com/u/24086?v=3","gravatar_id":"","url":"https://api.github.com/users/markstory","html_url":"https://github.com/markstory","followers_url":"https://api.github.com/users/markstory/followers","following_url":"https://api.github.com/users/markstory/following{/other_user}","gists_url":"https://api.github.com/users/markstory/gists{/gist_id}","starred_url":"https://api.github.com/users/markstory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markstory/subscriptions","organizations_url":"https://api.github.com/users/markstory/orgs","repos_url":"https://api.github.com/users/markstory/repos","events_url":"https://api.github.com/users/markstory/events{/privacy}","received_events_url":"https://api.github.com/users/markstory/received_events","type":"User","site_admin":false},"open_issues":26,"closed_issues":44,"state":"open","created_at":"2015-08-06T02:07:36Z","updated_at":"2015-08-19T20:24:43Z","due_on":"2015-08-26T04:00:00Z","closed_at":null},"comments":5,"created_at":"2015-08-18T19:49:26Z","updated_at":"2015-08-19T22:46:46Z","closed_at":"2015-08-19T02:01:18Z","body":"I'm using the following conditions for a where clause:\r\n`    $conditions = [ 'Things.id' => $id, 'Things.something_id' => $smt_id_array];`\r\nThis produces sql that correctly reads:\r\n`    Things.something_id = :c1`    which would seem to be correct.\r\n\r\nIf $smt_id_array has more than one element, the select produces the correct results.  However, if it contains a single element, the results will return only one record of the expected result set of 7.  \r\n\r\nI have not tested what happens if the $smt_id_array is an array but has NO elements or if it is NULL!  I have seen other items discussing the NULL case, but have not historically allowed that unless I wanted an IS NULL (or IS NOT NULL), but that is another discussion!\r\n\r\nAs a work around, I have changed the $conditions line above:\r\n`    $tmp_ids = (count($smt_id_array) > 1) ? $smt_id_array : $smt_id_array[0];`\r\n`    $conditions = [ 'Things.id' => $id, 'Things.something_id' => $tmp_ids];`\r\nwhich can properly handle both cases... The first generating an = and the second generating IN (...).\r\n\r\nCake tries to get it right by using the = or IN, but does not handle the = correctly.  Is this the desired behavior?  Seems that it should handle the single item array... even if it still produces an IN (:c1) instead of an = :c1\r\n"},"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/comments/132815164","html_url":"https://github.com/cakephp/cakephp/issues/7252#issuecomment-132815164","issue_url":"https://api.github.com/repos/cakephp/cakephp/issues/7252","id":132815164,"user":{"login":"glkaup","id":4357199,"avatar_url":"https://avatars.githubusercontent.com/u/4357199?v=3","gravatar_id":"","url":"https://api.github.com/users/glkaup","html_url":"https://github.com/glkaup","followers_url":"https://api.github.com/users/glkaup/followers","following_url":"https://api.github.com/users/glkaup/following{/other_user}","gists_url":"https://api.github.com/users/glkaup/gists{/gist_id}","starred_url":"https://api.github.com/users/glkaup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glkaup/subscriptions","organizations_url":"https://api.github.com/users/glkaup/orgs","repos_url":"https://api.github.com/users/glkaup/repos","events_url":"https://api.github.com/users/glkaup/events{/privacy}","received_events_url":"https://api.github.com/users/glkaup/received_events","type":"User","site_admin":false},"created_at":"2015-08-19T22:46:46Z","updated_at":"2015-08-19T22:46:46Z","body":"Then why can't you make the special case of a single item array still do an IN ($id) clause!  For crying out loud, a single item array is still an array!  Just because it only has one item is not the fault of the situation is it?"}}