{"action":"created","issue":{"url":"https://api.github.com/repos/doctrine/DoctrineMongoDBBundle/issues/300","labels_url":"https://api.github.com/repos/doctrine/DoctrineMongoDBBundle/issues/300/labels{/name}","comments_url":"https://api.github.com/repos/doctrine/DoctrineMongoDBBundle/issues/300/comments","events_url":"https://api.github.com/repos/doctrine/DoctrineMongoDBBundle/issues/300/events","html_url":"https://github.com/doctrine/DoctrineMongoDBBundle/issues/300","id":87387676,"number":300,"title":"ArrayCollection with Collection data","user":{"login":"joshlopes","id":3440849,"avatar_url":"https://avatars.githubusercontent.com/u/3440849?v=3","gravatar_id":"","url":"https://api.github.com/users/joshlopes","html_url":"https://github.com/joshlopes","followers_url":"https://api.github.com/users/joshlopes/followers","following_url":"https://api.github.com/users/joshlopes/following{/other_user}","gists_url":"https://api.github.com/users/joshlopes/gists{/gist_id}","starred_url":"https://api.github.com/users/joshlopes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshlopes/subscriptions","organizations_url":"https://api.github.com/users/joshlopes/orgs","repos_url":"https://api.github.com/users/joshlopes/repos","events_url":"https://api.github.com/users/joshlopes/events{/privacy}","received_events_url":"https://api.github.com/users/joshlopes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-11T15:38:08Z","updated_at":"2015-06-11T15:41:40Z","closed_at":null,"body":"Document\r\n````\r\n/**\r\n * @ODM\\Document(collection=\"products\")\r\n */\r\nclass Product \r\n{\r\n\r\n    /**\r\n     * @ODM\\Id\r\n     */\r\n    private $id;\r\n\r\n    /**\r\n     * @ODM\\Collection(name=\"gl\")\r\n     */\r\n    private $gallery;\r\n\r\n    public function __construct()\r\n    {\r\n        $this->gallery = new ArrayCollection();\r\n    }\r\n\r\n/**\r\n     * @return ArrayCollection\r\n     */\r\n    public function getGallery()\r\n    {\r\n        return $this->gallery;\r\n    }\r\n\r\n    /**\r\n     * @param ArrayCollection|array $gallery\r\n     */\r\n    public function setGallery($gallery)\r\n    {\r\n        $this->gallery = $gallery;\r\n    }\r\n\r\n    public function addGallery($img)\r\n    {\r\n        $this->gallery->add($img);\r\n    }\r\n}\r\n````\r\n\r\nTest\r\n````\r\nclass ProductRepositoryTest extends KernelTestCase\r\n{\r\n\r\n    /**\r\n     * @var \\Doctrine\\ORM\\EntityManager\r\n     */\r\n    private $em;\r\n    /**\r\n     * @var DocumentRepository\r\n     */\r\n    private $productRepo;\r\n\r\n    /**\r\n     * {@inheritDoc}\r\n     */\r\n    public function setUp()\r\n    {\r\n        self::bootKernel();\r\n        $this->em = static::$kernel->getContainer()\r\n            ->get('doctrine_mongodb')\r\n            ->getManager()\r\n        ;\r\n        $this->productRepo = $this->em->getRepository('ProductBundle:Product');\r\n        AnnotationDriver::registerAnnotationClasses();\r\n    }\r\n\r\n     /**\r\n     * @test\r\n     * @throws \\Doctrine\\ODM\\MongoDB\\MongoDBException\r\n     */\r\n    public function canCreateProducts()\r\n    {\r\n        $product = new Product();\r\n        $this->em->persist($product);\r\n        $this->em->flush($product);\r\n    }\r\n}\r\n````\r\n\r\nError:\r\n````\r\narray_values() expects parameter 1 to be array, object given\r\n /Users/luislopes/work/shopcade.admin/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Types/CollectionType.php:34\r\n /Users/luislopes/work/shopcade.admin/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php:93\r\n /Users/luislopes/work/shopcade.admin/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php:216\r\n /Users/luislopes/work/shopcade.admin/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php:1057\r\n /Users/luislopes/work/shopcade.admin/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php:447\r\n /Users/luislopes/work/shopcade.admin/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentManager.php:526\r\n /Users/luislopes/work/shopcade.admin/src/Shopcade/ProductBundle/Tests/Repository/ProductRepositoryTest.php:73\r\n````"},"comment":{"url":"https://api.github.com/repos/doctrine/DoctrineMongoDBBundle/issues/comments/111177437","html_url":"https://github.com/doctrine/DoctrineMongoDBBundle/issues/300#issuecomment-111177437","issue_url":"https://api.github.com/repos/doctrine/DoctrineMongoDBBundle/issues/300","id":111177437,"user":{"login":"joshlopes","id":3440849,"avatar_url":"https://avatars.githubusercontent.com/u/3440849?v=3","gravatar_id":"","url":"https://api.github.com/users/joshlopes","html_url":"https://github.com/joshlopes","followers_url":"https://api.github.com/users/joshlopes/followers","following_url":"https://api.github.com/users/joshlopes/following{/other_user}","gists_url":"https://api.github.com/users/joshlopes/gists{/gist_id}","starred_url":"https://api.github.com/users/joshlopes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshlopes/subscriptions","organizations_url":"https://api.github.com/users/joshlopes/orgs","repos_url":"https://api.github.com/users/joshlopes/repos","events_url":"https://api.github.com/users/joshlopes/events{/privacy}","received_events_url":"https://api.github.com/users/joshlopes/received_events","type":"User","site_admin":false},"created_at":"2015-06-11T15:41:40Z","updated_at":"2015-06-11T15:41:40Z","body":"Works if i change the constructor to private $this->gallery = []; or \r\n\r\n````\r\n$product->getGallery()->add('http://www.something.com/mainImage.png');\r\n$product->setGallery($product->getGallery()->toArray());\r\n````\r\n\r\nIt doesnt make sense CollectionType doesnt look for the ArrayCollection type and converts it to array instead using the array_values on top of the object. Correct me if i am wrong."}}