{"action":"created","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/7743","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/7743/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/7743/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/7743/events","html_url":"https://github.com/cakephp/cakephp/issues/7743","id":119016289,"number":7743,"title":"Database Query unusual error handling","user":{"login":"ProFire","id":277493,"avatar_url":"https://avatars.githubusercontent.com/u/277493?v=3","gravatar_id":"","url":"https://api.github.com/users/ProFire","html_url":"https://github.com/ProFire","followers_url":"https://api.github.com/users/ProFire/followers","following_url":"https://api.github.com/users/ProFire/following{/other_user}","gists_url":"https://api.github.com/users/ProFire/gists{/gist_id}","starred_url":"https://api.github.com/users/ProFire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ProFire/subscriptions","organizations_url":"https://api.github.com/users/ProFire/orgs","repos_url":"https://api.github.com/users/ProFire/repos","events_url":"https://api.github.com/users/ProFire/events{/privacy}","received_events_url":"https://api.github.com/users/ProFire/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-26T10:38:08Z","updated_at":"2015-11-26T12:09:49Z","closed_at":null,"body":"Hello bakers,\r\n\r\nI recently encountered a problem with a database query error on CakePHP 3.1.4, an error that didn't occur in CakePHP 3.1.1. I believe this error is both my end and CakePHP's end. Took me hours to figure out where I went wrong.\r\n\r\n### Error message encountered:\r\nInvalidArgumentException: Cannot convert value to string in C:\\wamp\\www\\SocialSoundfyr2\\vendor\\cakephp\\cakephp\\src\\Database\\Type\\StringType.php\r\n\r\n### Error trigger:\r\n```php\r\n$table = TableRegistry::get(\"ModelName\");\r\nreturn $table ->find(\"all\", [\r\n    \"conditions\" => [\r\n        \"ModelName.product_id\" => $this->_properties[\"id\"],\r\n       \"AssocModelName.status\" => [0, 1],// This code worked in CakePHP 3.1.1\r\n    ],\r\n]);\r\n```\r\n\r\n### Solution:\r\n```php\r\n$table = TableRegistry::get(\"ModelName\");\r\nreturn $table ->find(\"all\", [\r\n    \"conditions\" => [\r\n        \"ModelName.product_id\" => $this->_properties[\"id\"],\r\n       \"AssocModelName.status IN\" => [0, 1],// This code fixed the error\r\n    ],\r\n]);\r\n```\r\n\r\n### Debugging Procedures:\r\nWhat I couldn't figure out is why the error message is totally unrelated to my mistake. Took me hours of tracing the error to find out where I did wrong. Here's some of my findings through my tracing:\r\n\r\n**Level 1**\r\nAn array was passed to this class that's suppose to take in String type.\r\n>Cake\\Database\\Type\\StringType::toDatabase()\r\n$value = [0,1];\r\n\r\n**Level 2**\r\nThe type was determined to be string when the value is actually an Array type.\r\n>Cake\\Database\\TypeConverterTrait::cast()\r\n$value = [0,1]\r\n$type = \"string\"\r\n\r\n**Level 3**\r\nThe type passed to this class::function was null, thus at line 67, it was determined to be \"string\".\r\n>Cake\\Database\\Statement\\PDOStatement::bindValue()\r\n$type = null\r\n\r\n**Level 4**\r\nThe types array had a blank/null value for the specific key in the array.\r\n>Cake\\Database\\Statement\\StatementDecorator::bind()\r\n$params = [2, [0,1]]\r\n$types = [\"integer\", null]\r\n\r\n### The Machine\r\nOS: Windows 7\r\nStack: WAMP 64bit\r\nPHP: 5.5.12\r\nDatabase: Sqlite"},"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/comments/159897746","html_url":"https://github.com/cakephp/cakephp/issues/7743#issuecomment-159897746","issue_url":"https://api.github.com/repos/cakephp/cakephp/issues/7743","id":159897746,"user":{"login":"lorenzo","id":37621,"avatar_url":"https://avatars.githubusercontent.com/u/37621?v=3","gravatar_id":"","url":"https://api.github.com/users/lorenzo","html_url":"https://github.com/lorenzo","followers_url":"https://api.github.com/users/lorenzo/followers","following_url":"https://api.github.com/users/lorenzo/following{/other_user}","gists_url":"https://api.github.com/users/lorenzo/gists{/gist_id}","starred_url":"https://api.github.com/users/lorenzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lorenzo/subscriptions","organizations_url":"https://api.github.com/users/lorenzo/orgs","repos_url":"https://api.github.com/users/lorenzo/repos","events_url":"https://api.github.com/users/lorenzo/events{/privacy}","received_events_url":"https://api.github.com/users/lorenzo/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T12:09:49Z","updated_at":"2015-11-26T12:09:49Z","body":"I can try to improve the error message."}}