1

Using Symfony 4.1, SonataUserBundle with FOSUserBundle (Current)

Followed the instructions, created wrapper class for User, added ORM tablename hint as well.

namespace App\Application\Sonata\UserBundle\Entity;

use Sonata\UserBundle\Entity\BaseUser as BaseUser;

use Doctrine\ORM\Mapping as ORM;

/**
 * This file has been generated by the SonataEasyExtendsBundle.
 * @ORM\Entity(name="aegis_user")
 * @link https://sonata-project.org/easy-extends
 *
 * References:
 * @link http://www.doctrine-project.org/projects/orm/2.0/docs/reference/working-with-objects/en
 */
class User extends BaseUser
{
    /**
     * @var int $id
     */
    protected $id;

    /**
     * Get id.
     *
     * @return int $id
     */
    public function getId()
    {
        return $this->id;
    }
}    

However, the table names generated (doctrine migration) are still fos_user_user, fos_user_group etc.

$this->addSql('CREATE TABLE fos_user_group (id INT ...
$this->addSql('CREATE TABLE fos_user_user (id INT ...
$this->addSql('CREATE TABLE fos_user_user_group (user_id INT ...

I need the table name prefix at least to change to xxx_user, xxx_group.

How do I change the names of the tables that FosUserBundle generates without modifying the bundle code ?

Thanks.

Jack
  • 99
  • 5
  • Note: I have also tried the @ORM\Table(name="aegis_user") hint. Did not help. – Jack Jul 09 '18 at 11:56
  • I added mapping configuration to doctine.yaml ApplicationSonataUserBundle: type: annotation And it started factoring in the annotations, however, now a different issue has come up. Doctrine now throws up "No Primary Key Defined for Entity Error" No identifier/primary key specified for Entity "App\Application\Sonata\User Bundle\Entity\User" sub class of "Sonata\UserBundle\Entity\BaseUser". Every Entity must have an identifier/primary key. I have declared Id column annotation, but doctrine is ignoring it, most probably due to conflict with bundle configuration. – Jack Jul 10 '18 at 05:35

2 Answers2

0

You are searching for

* @ORM\Table(name="table_name")

not

* @ORM\Entity(name="aegis_user")
Jim Panse
  • 2,220
  • 12
  • 34
  • Yes, aware of that part, still did not make a difference. Also, there is a join table fos_user_user_group – Jack Jul 09 '18 at 11:55
  • I hope you did not delete your Entity Annotation ... I tried that example right now. It works – Jim Panse Jul 09 '18 at 12:00
  • I was able to go one step further, but now I am getting a different issue, I created another thread for it: https://stackoverflow.com/questions/51258026/sonatauserbundle-fosuserbundle-annotation-issue-doctrine-primary-key-error – Jack Jul 10 '18 at 05:56
0

To change group table name you have to edit sonata user config

config/packages/sonata_user.yaml

table:
    user_group: "my_custom_user_group_association_table_name"

for more details it's documented here

Aref Ben Lazrek
  • 1,056
  • 1
  • 11
  • 19