{"action":"opened","issue":{"url":"https://api.github.com/repos/lox/pheasant/issues/130","labels_url":"https://api.github.com/repos/lox/pheasant/issues/130/labels{/name}","comments_url":"https://api.github.com/repos/lox/pheasant/issues/130/comments","events_url":"https://api.github.com/repos/lox/pheasant/issues/130/events","html_url":"https://github.com/lox/pheasant/issues/130","id":68482877,"number":130,"title":"Double hydrating when using `includes()`?","user":{"login":"bjornpost","id":48628,"avatar_url":"https://avatars.githubusercontent.com/u/48628?v=3","gravatar_id":"","url":"https://api.github.com/users/bjornpost","html_url":"https://github.com/bjornpost","followers_url":"https://api.github.com/users/bjornpost/followers","following_url":"https://api.github.com/users/bjornpost/following{/other_user}","gists_url":"https://api.github.com/users/bjornpost/gists{/gist_id}","starred_url":"https://api.github.com/users/bjornpost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjornpost/subscriptions","organizations_url":"https://api.github.com/users/bjornpost/orgs","repos_url":"https://api.github.com/users/bjornpost/repos","events_url":"https://api.github.com/users/bjornpost/events{/privacy}","received_events_url":"https://api.github.com/users/bjornpost/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-14T20:02:22Z","updated_at":"2015-04-14T20:02:22Z","closed_at":null,"body":"Just fiddled around with `includes()` again and noticed that it tries to hydrate objects twice. Most of the time it's just inefficient. But when using the DateTime Type, it throws an exception saying \"DateTime::__construct() expects parameter 1 to be string, object given\".\r\n\r\nAfter some digging; I found that `Schema::hydrate()` is called twice for included DomainObjects. First, it's called from `\\Pheasant\\Collection::hydrate()` ([src](https://github.com/lox/pheasant/blob/master/lib/Pheasant/Collection.php#L40)), second time it's called from `Relationship::get()`, (f.e. BelongsTo ([src](https://github.com/lox/pheasant/blob/master/lib/Pheasant/Relationships/BelongsTo.php#L36))).\r\n\r\nJust calling `return $cached;` in BelongsTo.php fixes the issue, but I'm not sure about possible unwanted side effects.\r\n\r\n/cc @Jud "}}