Basically, it's the beginning of taxonomy system with some of them nestable, and some not. I started to try making 2 layers of abstract classes (Taxonomy and OfferCategory) because none of them can be used as a final entity. I used MappedSuperClass, but I got following error :
[Doctrine\ORM\ORMException]
Column name `id` referenced for relation from LCH\CatalogBundle\Entity\HomeOfferCategory towards LCH\CatalogBund le\Entity\OfferCategory does not exist.
My primary key field is id...
In a more general point of view, what's the best implementation for my scheme provided with Doctrine?
Thanks !
EDIT : I tried to transpose all OfferCategory members directly in my RootOfferCategory class. By changing th targetENtity on both sides, no more error. Meaning you can't self reference a mapped super class?
Taxonomy :
/**
* Class Taxonomy
* @package LCH\CatalogBundle\Entity
* @ORM\MappedSuperclass
*/
abstract class Taxonomy implements TaxonomyInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string the category name
* @ORM\Column(name="name", type="string", length=255)
*/
protected $name;
}
**OfferCategory : **
/**
* OfferCategory
* @ORM\MappedSuperclass
*/
abstract class OfferCategory extends Taxonomy
{
/**
* @var OfferCategory the category parent
* @ORM\ManyToOne(targetEntity="LCH\CatalogBundle\Entity\OfferCategory",inversedBy="children", cascade={"persist"})
* @ORM\JoinColumn(name="parent_id", referenceColumnName="id")
*/
protected $parent;
/**
* @var OfferCategory the children categories
* @ORM\OneToMany(targetEntity="LCH\CatalogBundle\Entity\OfferCategory",mappedBy="parent", cascade={"persist"})
*/
protected $children;
}
RootOfferCategory
/**
* RootOfferCategory
* Represents one root top category
* @ORM\Table()
* @ORM\Entity(repositoryClass="LCH\CatalogBundle\Entity\RootOfferCategoryRepository")
*/
class RootOfferCategory extends OfferCategory
{
}
