user - entities in different bundles -
user - entities in different bundles -
i'm using symfony 2 , have 2 entities in different bundles like:
//this class overrides fos_user class //user\userbundle\entity\user class user extends baseuser { //.. /** * @orm\onetomany(targetentity="news\adminbundle\entity\news", mappedby="author_id") */ protected $news_author; //... } //news\adminbundle\entity\news class news { //... /** * @orm\manytoone(targetentity="\user\userbundle\entity\user", inversedby="news_author") * @orm\joincolumn(name="author_id", referencedcolumnname="id") */ protected $news_author; //... }
both classes (entities) works fine. have setup fos_user bundle registration , other stuff. same if news class. build relation between 2 classes oneto many (user -> news) shown in code. works fine without errors , can add together news belongs user. problem when build form entity class like:
->add('year', 'entity', array( 'class' => 'newsadminbundle:news', 'query_builder' => function(entityrepository $er) { homecoming $er->createquerybuilder('u') ->groupby('u.year') ->orderby('u.year', 'desc'); },))
this form shows me years when news posted (like archive). years showing fine, when submit (post) form i've got error:
class user\userbundle\entity\news not exist
i figure out error connected sentence
$form->bindrequest($request);
the problem because have 2 entities in different bundles. how can solve error?
edit: solved problem. when run
php app/console doctrine:generate:entities user php app/console doctrine:generate:entities news
then doctrine generate getters , setters in user , news. in entity news generates method
/** * add together news_author * * @param user\userbundle\entity\news $newsauthor */ public function addnews(user\userbundle\entity\news $newsauthor) { $this->news_author[] = $newsauthor; }
i not paying attending method , alter this
/** * add together news_author * * @param news\adminbundle\entity\news $newsauthor */ public function addnews(news\adminbundle\entity\news $newsauthor) { $this->news_author[] = $newsauthor; }
now works fine. answers.
/** * @orm\manytoone(targetentity="user\userbundle\entity\user", inversedby="news_author") * @orm\joincolumn(name="author_id", referencedcolumnname="id") */ protected $news_author;
you have remove prefix backslash – see note in doctrine documentation
user symfony2 entities
Comments
Post a Comment