How do you create ManyToOne relation within single supermapped class

I am creating a simple CMS Bundle for my headless symfony backend and I’m trying to map Page to Page with parent and child relation(Many children to one parent) and I have this class mapped superclass to create reusable code, this is a minified sample on what I’m trying to archive:


use DoctrineORMMapping as ORM;

/**
 * @ORMMappedSuperclass()
 */
class Test
{
    /**
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function getId()
    {
        return $this->id;
    }

    /**
     * @ORMManyToOne(targetEntity="ZieburaCMSBundleEntityTest")
     */
    protected $parent;

    public function getParent()
    {
        return $this->parent;
    }

    public function setParent($parent)
    {
        $this->parent = $parent;
    }
}

Then I’m extending this class as a normal entity to create DB table

<?php

namespace AppEntity;
use DoctrineORMMapping as ORM;
use ZieburaCMSBundleEntityTest as BaseTest;

/**
 * @ORMTable(name="test")
 * @ORMEntity(repositoryClass="AppRepositoryTestRepository")
 */
class Test extends BaseTest
{
}

The issue is that I’m getting this doctrine exception

Column name `id` referenced for relation from AppEntityTest towards ZieburaCMSBundleEntityTest does not exist. 

I don’t quite understand why it produces this error or is the thing that I’m trying to archive impossible, I already did relations on mapped superclasses but it was 2 or more tables and not just a single on. I already tried creating $children field but it didnt worked and still produced above error. Did anyone try to create something simmilar? I couldn’t find anything about this in doctrine docs, only found how to map 2 different superclasses. I suppose the easy way out would be to specify the relation in App namespace not in the Bundle but that pretty much destroys the purpose of reusable code if I’d have to declare that in every project I use the bundle. I believe in stack let’s figure this out. Thanks!

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *