php - Symfony2 - Doctrine - Entity relationship between 2 bundles -


i can't figure out how can have entity relationship between 2 bundles.

the closest i've been succeed far this:

user entity:

<?php namespace acme\authbundle\entity; use fos\userbundle\entity\user baseuser; use doctrine\orm\mapping orm;  use symfony\component\validator\constraints assert;  use doctrine\common\collections\arraycollection;  /**  * @orm\entity  * @orm\table(name="fos_user")  */ class user extends baseuser {     /**      * @orm\id      * @orm\column(type="integer")      * @orm\generatedvalue(strategy="auto")      */     protected $id;      //...      /**      * @orm\onetomany(targetentity="acme\newsbundle\entity\article", mappedby="author")      */     protected $articles;       //... 

article entity:

<?php namespace acme\newsbundle\entity;  use doctrine\orm\mapping orm;  /**  * @orm\entity(repositoryclass="acme\newsbundle\entity\articlerepository")  * @orm\table(name="articles")  */ class article {     /**      * @orm\id      * @orm\column(type="integer")      * @orm\generatedvalue(strategy="auto")      */     protected $id;      //...      /**      * @orm\manytoone(targetentity="acme\authbundle\entity\user", inversedby="articles")      */      protected $author;       //... 

when generating entities , updating database, no errors , relation correctly set in db.

but when try fetch articles this:

class acme\authbundle\entity\article not exist 500 internal server error - reflectionexception  

note user entity in authbundle , article entity in newsbundle.

thanks.

you need specify name of entity class when defining one-to-many, many-to-one relations. still specifying acme\authbundle\entity\user not aief\authbundle\entity\user targetentity.

the same article , article repository.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -