Get table name of entity class
Solution 1:
From within a controller you would use:
$em = $this->getDoctrine()->getManager();
$tableName = $em->getClassMetadata('StoreBundle:User')->getTableName();
Note that the getClassMetadata
method returns a bunch of interesting info about the entity.
Solution 2:
I needed to find out the name of a mapping Table in a many-to-many relationship (using FOSUserBundle). Maybe this helps someone:
$groupAssociation = $this->getEntityManager()
->getClassMetadata('UOACLBundle:User')
->getAssociationsByTargetClass(Group::class);
// 'groups' is the name of the property in my User Class
$mappingTable = $groupAssociation['groups']['joinTable']['name'];