php - Doctrine collection is null upon object initialization [In some cases only] -


this problem: create object, collection object. objects, in controllers, collections return empty collectionarray object, returns null.

reading in so, better initialize manytomany relationships in entities constructor, case? documented?

this example of problem:

$p = new person(); $p->getrelatives(); // null, should empty collectionarray. 

in mean time, in controller class...

$w = new woman(); w->getmen(); // returns empty collectionarray class -.- 

hope guys can point me in right direction, don't want go through entities , create constructor them because of this!

besides, whats annoying non deterministic behavior in collections returned.

and that's reason, why documentation says, all collections should initialized:

<?php use doctrine\common\collections\arraycollection;  /** @entity */ class user {     /** @manytomany(targetentity="group") */     private $groups;      public function __construct()     {         $this->groups = new arraycollection();     }      public function getgroups()     {         return $this->groups;     } } 

and time, if collection null or not null, if not initialised determenistic. without initialisation $groups field contains instance of doctrine\common\collections\collection if user retrieved doctrine, not after instantiated fresh instance of user. when user entity still new $groups null.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -