{"action":"created","issue":{"url":"https://api.github.com/repos/jenssegers/laravel-mongodb/issues/329","labels_url":"https://api.github.com/repos/jenssegers/laravel-mongodb/issues/329/labels{/name}","comments_url":"https://api.github.com/repos/jenssegers/laravel-mongodb/issues/329/comments","events_url":"https://api.github.com/repos/jenssegers/laravel-mongodb/issues/329/events","html_url":"https://github.com/jenssegers/laravel-mongodb/issues/329","id":44087072,"number":329,"title":"\"Serialization of 'Closure' is not allowed\" when caching object after adding to \"embedsMany\" attribute","user":{"login":"rms2219","id":4907425,"avatar_url":"https://avatars.githubusercontent.com/u/4907425?v=3","gravatar_id":"","url":"https://api.github.com/users/rms2219","html_url":"https://github.com/rms2219","followers_url":"https://api.github.com/users/rms2219/followers","following_url":"https://api.github.com/users/rms2219/following{/other_user}","gists_url":"https://api.github.com/users/rms2219/gists{/gist_id}","starred_url":"https://api.github.com/users/rms2219/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rms2219/subscriptions","organizations_url":"https://api.github.com/users/rms2219/orgs","repos_url":"https://api.github.com/users/rms2219/repos","events_url":"https://api.github.com/users/rms2219/events{/privacy}","received_events_url":"https://api.github.com/users/rms2219/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jenssegers/laravel-mongodb/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-09-26T17:37:07Z","updated_at":"2015-05-06T07:28:10Z","closed_at":null,"body":"I have a \"Contract\" object which embeds many \"Project\" objects. The database interactions are working fine. I can add (associate) a new project to a contract and save the contract just fine. When I try to put that recently saved object into my cache, I get the exception: \"Serialization of 'Closure' is not allowed\".\r\n\r\nHere is a bit of test code that shows the issue:\r\n\r\n```\r\nuse Jenssegers\\Mongodb\\Model;\r\n\r\nclass Contract extends Model {\r\n    public function projects()\r\n    {\r\n         return $this->embedsMany('Project');\r\n    }\r\n}\r\n\r\nclass Project extends Model {}\r\n\r\n// routes.php\r\n    Route::post('contracts/{id}/projects', function($id) {\r\n\r\n        $contract = Cache::get('Contracts_' . $id);\r\n\r\n        if(!$contract) {\r\n            $contract = Contract::findOrFail($id);\r\n        }\r\n\r\n        $project = new Project();\r\n        $project->projectName = 'new project';\r\n\r\n        $contract->projects()->save($project); // This works just fine\r\n\r\n        Cache::forever('Contracts_' . $id, $contract); // Exception thrown here\r\n    });\r\n```\r\n\r\nHow can I cache the updated contract?"},"comment":{"url":"https://api.github.com/repos/jenssegers/laravel-mongodb/issues/comments/99353535","html_url":"https://github.com/jenssegers/laravel-mongodb/issues/329#issuecomment-99353535","issue_url":"https://api.github.com/repos/jenssegers/laravel-mongodb/issues/329","id":99353535,"user":{"login":"jenssegers","id":194377,"avatar_url":"https://avatars.githubusercontent.com/u/194377?v=3","gravatar_id":"","url":"https://api.github.com/users/jenssegers","html_url":"https://github.com/jenssegers","followers_url":"https://api.github.com/users/jenssegers/followers","following_url":"https://api.github.com/users/jenssegers/following{/other_user}","gists_url":"https://api.github.com/users/jenssegers/gists{/gist_id}","starred_url":"https://api.github.com/users/jenssegers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenssegers/subscriptions","organizations_url":"https://api.github.com/users/jenssegers/orgs","repos_url":"https://api.github.com/users/jenssegers/repos","events_url":"https://api.github.com/users/jenssegers/events{/privacy}","received_events_url":"https://api.github.com/users/jenssegers/received_events","type":"User","site_admin":false},"created_at":"2015-05-06T07:28:10Z","updated_at":"2015-05-06T07:28:10Z","body":"This is indeed an issue with the current implementation of embedded models. I'm trying to get this fixed in the v3 release."}}