{"action":"opened","issue":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/10573","labels_url":"https://api.github.com/repos/phalcon/cphalcon/issues/10573/labels{/name}","comments_url":"https://api.github.com/repos/phalcon/cphalcon/issues/10573/comments","events_url":"https://api.github.com/repos/phalcon/cphalcon/issues/10573/events","html_url":"https://github.com/phalcon/cphalcon/issues/10573","id":92155248,"number":10573,"title":"Problem with nullable columns and cast on hydrate","user":{"login":"ogarbe","id":1395245,"avatar_url":"https://avatars.githubusercontent.com/u/1395245?v=3","gravatar_id":"","url":"https://api.github.com/users/ogarbe","html_url":"https://github.com/ogarbe","followers_url":"https://api.github.com/users/ogarbe/followers","following_url":"https://api.github.com/users/ogarbe/following{/other_user}","gists_url":"https://api.github.com/users/ogarbe/gists{/gist_id}","starred_url":"https://api.github.com/users/ogarbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ogarbe/subscriptions","organizations_url":"https://api.github.com/users/ogarbe/orgs","repos_url":"https://api.github.com/users/ogarbe/repos","events_url":"https://api.github.com/users/ogarbe/events{/privacy}","received_events_url":"https://api.github.com/users/ogarbe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-30T17:44:16Z","updated_at":"2015-06-30T17:44:16Z","closed_at":null,"body":"The cast_on_hydrate function creates a bug when a column is nullable\r\n\r\nTable document : \r\nid int\r\nname string\r\nparent_document int (nullable) which is a FK to document.id\r\n\r\nmy model Document can have a parent document which is Document->Parent but a document can have \"no parent\"\r\n\r\nif i activate cast on hydrate => all documents with no parents become document with parent document 0 (which does not exists..)\r\n\r\nin my opinion a test should be made here https://github.com/phalcon/cphalcon/blob/2.0.x/phalcon/mvc/model.zep#L541-L555 to validate value is not empty and replace castValue by NULL in this case.\r\n\r\n@andresgutierrez what do you think of that ?\r\n"}}