Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 Relationships using Interfaces results in duplicated table
    text
    copied!<p>I'm trying to relate an entity in one bundle with another in another bundle to make the second one independent from the first one, and be able to reuse it.</p> <p>I'm following <a href="http://symfony.com/doc/current/cookbook/doctrine/resolve_target_entity.html" rel="nofollow noreferrer">this</a> documentation and <a href="https://stackoverflow.com/a/18782956/1209290">this</a> StackOverflows answer.</p> <p>In the reusable bundle I have a Folder, File a that belongs to the folder and and interface like this:</p> <pre><code>namespace Acme\FolderBundle\Entity; /** * @ORM\Entity */ class Folder implements FolderInterface { // Has many files } namespace Acme\FolderBundle\Entity; interface FolderInterface { // no methods here } namespace Acme\FolderBundle\Entity; /** * @ORM\Entity */ class File { // Belongs to one folder } </code></pre> <p>And on the other bundle just one class:</p> <pre><code>namespace Acme\NewBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Acme\FolderBundle\Entity\Folder as BaseFolder; use Acme\FolderBundle\Entity\FolderInterface; /** * @ORM\Entity */ class Folder extends BaseFolder implements FolderInterface { // Has many files } </code></pre> <p>And the config.yml's ORM configuration:</p> <pre><code>orm: auto_generate_proxy_classes: %kernel.debug% auto_mapping: true resolve_target_entities: Acme\FolderBundle\Entity\FolderInterface: Acme\NewBundle\Entity\Folder </code></pre> <p>If I try to update my database schema, I get the following error:</p> <pre><code>[Doctrine\DBAL\Schema\SchemaException] The table with name 'foldersDatabase.folder' already exists. </code></pre> <p>To get this working, I have to explicitly change one of the Folder's Entities table:</p> <pre><code>namespace Acme\FolderBundle\Entity; /** * @ORM\Entity * @ORM\Table(name="distributed_folder") */ class Folder implements FolderInterface { // Has many files } </code></pre> <p>Then, everything works but I get stuck with a table in my database (distributed_folder) that is never used.</p> <p>Thanks a lot in advance!!</p> <p>EDIT: Fixed the annotation in the FolderInterface</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload