php - Doctrine/Symfony - I have some errors. Something wrong with my relations -


i exception entities. tried play them. checked on google relation appropriate entities... couldn't find best configuration.

i'm making website can create albums.

a user can have multiple albums.so have entity album , have inside user property :

/** * album * * @orm\table(name="album") * @orm\entity(repositoryclass="moodress\bundle\albumbundle\entity\albumrepository") */  class album { /**  * @var integer  *  * @orm\column(name="id", type="integer")  * @orm\id  * @orm\generatedvalue(strategy="auto")  */ private $id;  /**   ** @orm\manytoone(targetentity="moodress\bundle\userbundle\entity\user")  ** @orm\joincolumn(nullable=false)   */ private $user;  /**  * @var string  *  * @orm\column(name="name", type="string", length=255)  */ private $name;  /**  * @var \datetime  *  * @orm\column(name="creationdate", type="datetime")  */ private $creationdate;  /**  * @var \datetime  *  * @orm\column(name="modificationdate", type="datetime")  */ private $modificationdate;   /**  * @orm\onetomany(targetentity="moodress\bundle\albumbundle\entity\picture", cascade={"persist"}, mappedby="album")  */  private $pictures;  /**  * constructor  */ public function __construct() {     $this->creationdate = new \datetime();     $this->modificationdate = new \datetime(); }  // , set } 

however, when user subscribe on website, create default album called upload want keep in user class.

this tried :

/** * user *     * @orm\entity * @orm\table(name="user") */ class user extends baseuser   { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */  protected $id;  /**  * @orm\onetoone(targetentity="moodress\bundle\albumbundle\entity\album", cascade={"persist"})  */  protected $albumupload;   // , set } 

i have error : undefined index: album in /users/sandro/sites/moodress-website/symfony/vendor/doctrine/orm/lib/doctrine/orm/persisters/basicentitypersister.php line 1608. error appears directly when serialize entity has user object...

the error caused association annotation of $albumupload property in user class.

doctrine assumes have $album property in album entity when use @orm\onetoone(targetentity="moodress\bundle\albumbundle\entity\album") association in user entity.

try

/**   ** @orm\manytoone(targetentity="moodress\bundle\userbundle\entity\user", inversedby="albums")  ** @orm\joincolumn(nullable=false)   */ private $user; 

in album entity and

/**  * @orm\onetomany(targetentity="moodress\bundle\albumbundle\entity\album", mappedby="user", cascade={"persist"})  */  protected $albums; 

in user entity. in addition please add $this->albums = new arraycollection() user::__construct().

now if want add , keep default album users should implement somewhere in business logic. figure out way identify default album in collection of albums , prevent deletion item.

hope helps.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -