Annotations in extended Sonata user class not being read
Asked Answered
V

2

6

I extended the user bundle from the Sonata project with Sonata EasyExtends bundle. It is placed under src/Application/Sonata/UserBundle by default

Now I want to customize the extended class and add some fields. I notice though that annotations are not being processed, I need to define the mappings in src/Application/Sonata/UserBundle/Resources/config/doctrine/User.orm.xml

Is there any way to make use of the annotations instead of the XML file? I think it will solve a lot of my problems with referencing the user class, as now the command

php app/console doctrine:schema:update --force

doesnt seem to recognize the annotations..

Vertu answered 26/12, 2012 at 14:32 Comment(0)
S
10

Delete Application/Sonata/UserBundle/Resources/config/doctrine at first

and later change Entity/User.php and Entity/Group.php to annotation type:

<?php

namespace Application\Sonata\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;

/**
 * User
 *
 * @ORM\Table(name="fos_user_user")
 * @ORM\Entity
 */

class User extends BaseUser
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=127)
     */
    protected $test;
}
<?php

namespace Application\Sonata\UserBundle\Entity;

use Sonata\UserBundle\Entity\BaseGroup as BaseGroup;
use Doctrine\ORM\Mapping as ORM;

/**
 * Group
 *
 * @ORM\Table(name="fos_user_group")
 * @ORM\Entity
 */
class Group extends BaseGroup
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

}

In the end you should type: php app/console doctrine:schema:update --force and everything should works pretty.

Sansbury answered 2/1, 2013 at 12:34 Comment(0)
B
-1

In resume, if you use XML, annotations does not rules.

If you delete config/doctrine folder, it will look for annotations, and there, you can put what you want.

Bussey answered 28/2, 2015 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.