{"action":"opened","issue":{"url":"https://api.github.com/repos/TomHAnderson/zf-oauth2-doctrine/issues/50","labels_url":"https://api.github.com/repos/TomHAnderson/zf-oauth2-doctrine/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/TomHAnderson/zf-oauth2-doctrine/issues/50/comments","events_url":"https://api.github.com/repos/TomHAnderson/zf-oauth2-doctrine/issues/50/events","html_url":"https://github.com/TomHAnderson/zf-oauth2-doctrine/issues/50","id":108493172,"number":50,"title":"How to add scopes to a client","user":{"login":"chateaux","id":5870036,"avatar_url":"https://avatars.githubusercontent.com/u/5870036?v=3","gravatar_id":"","url":"https://api.github.com/users/chateaux","html_url":"https://github.com/chateaux","followers_url":"https://api.github.com/users/chateaux/followers","following_url":"https://api.github.com/users/chateaux/following{/other_user}","gists_url":"https://api.github.com/users/chateaux/gists{/gist_id}","starred_url":"https://api.github.com/users/chateaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chateaux/subscriptions","organizations_url":"https://api.github.com/users/chateaux/orgs","repos_url":"https://api.github.com/users/chateaux/repos","events_url":"https://api.github.com/users/chateaux/events{/privacy}","received_events_url":"https://api.github.com/users/chateaux/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-26T20:15:46Z","updated_at":"2015-09-26T20:15:46Z","closed_at":null,"body":"I am using forms to add a new client which has a selection of grant types and scopes. In my form I have added scopes using an ObjectSelect as so:\r\n\r\n        $this->add(\r\n            [\r\n                'type' => 'DoctrineModule\\Form\\Element\\ObjectSelect',\r\n                'name' => 'scope',\r\n                'options' => [\r\n                    'object_manager' => $this->objectManager,\r\n                    'target_class'   => 'ZF\\OAuth2\\Doctrine\\Entity\\Scope',\r\n                    'property'       => 'scope',\r\n                    'label' => 'Scope',\r\n                    'instructions' => ''\r\n                ],\r\n                'attributes' => [\r\n                    'required' => 'required',\r\n                    'multiple' => true,\r\n                    'class' => 'form-control input-medium select2me',\r\n                ]\r\n            ]\r\n        );\r\n\r\nThe form renders as expected however once submitted and persisted I get the following error:\r\n\r\nCatchable fatal error: Argument 1 passed to ZF\\OAuth2\\Doctrine\\Entity\\Client::addScope() must be an instance of ZF\\OAuth2\\Doctrine\\Entity\\Scope, instance of Doctrine\\Common\\Collections\\ArrayCollection given, called in /var/www/cloud/vendor/doctrine/doctrine-module/src/DoctrineModule/Stdlib/Hydrator/Strategy/AllowRemoveByValue.php on line 71 and defined in /var/www/cloud/vendor/zfcampus/zf-oauth2-doctrine/src/Entity/Client.php on line 466\r\n\r\n**This error makes sense since the client scope methods are as so:**\r\n\r\n public function addScope(Scope $scope)\r\n    {\r\n        $this->scope[] = $scope;\r\n        return $this;\r\n    }\r\n\r\npublic function removeScope(Scope $scope)\r\n    {\r\n        $this->scope->removeElement($scope);\r\n    }\r\n\r\n**If I dump my form post it looks as such:**\r\n\r\narray (size=3)\r\n  'csrfcheck' => string '5429cd84d542f64c82fd954231c0b7a2-7231f4072ce730bfc6d3fc831eaecdae' (length=65)\r\n  'client' => \r\n    array (size=7)\r\n      'id' => string '4' (length=1)\r\n      'clientId' => string 'test_client' (length=11)\r\n      'grantType' => \r\n        array (size=2)\r\n          0 => string 'implicit' (length=8)\r\n          1 => string 'urn:ietf:params:oauth:grant-type:jwt-bearer' (length=43)\r\n      'scope' => \r\n        array (size=2)\r\n          0 => string '1' (length=1)\r\n          1 => string '2' (length=1)\r\n      'redirectUri' => string 'http://www.example.com' (length=22)\r\n      'password' => string '' (length=0)\r\n      'passwordRepeat' => string '' (length=0)\r\n  'submit' => string 'Submit' (length=6)\r\n\r\n**So what is the process to add scopes?**\r\n\r\nI was thinking of changing the field name to something like myScopes and then once I have persisted the client to add the scopes one at a time. The other alternative was to load each scopeObject and add the client to it.\r\n\r\nKindly advise"}}