views:

33

answers:

1

I am trying to follow the advice from the doctrine docs on this page - initialising a class member with the ArrayCollection. All works well for the example given in the docs. I'm trying to do it with an inherited class but get an error saying:

Class Doctrine\Common\Collections\ArrayCollection is not a valid entity or mapped super class

Inherited class:

/**

* @Entity * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({"user" = "App_User", "group" = "App_Group"}) */

abstract class App_Acl_Role_Abstract implements Zend_Acl_Role_Interface {

/** * @ManyToOne(targetEntity="App_Acl_Role_Abstract", inversedBy="children", cascade={"persist"}) */ private $parents;

/** * @OneToMany(targetEntity="App_Acl_Role_Abstract", mappedBy="parents", cascade={"persist"}) */ private $children;

public function __construct() { $this->parents = new Doctrine\Common\Collections\ArrayCollection(); $this->children = new Doctrine\Common\Collections\ArrayCollection(); } }

Inheriting class:

/** * @Entity * @Table(name="App_User") */ class App_User extends App_Acl_Role_Abstract { ... }

When I move the constructor to the inheriting class all works fine. But it would be much neater to have them in the inherited abstract class. Why does it not work? Is it possible?

A: 

My bad. I stuffed up the mapping. This is the mapping I'm now using:

/**
 * @ManyToMany(targetEntity="App_Acl_Role_Abstract", cascade={"persist"})
 * @JoinTable(name="role_parents",
 *      joinColumns={@JoinColumn(name="role_id", referencedColumnName="id")},
 *      inverseJoinColumns={@JoinColumn(name="parent_id", referencedColumnName="id", unique=true)}
 *      )
 */
private $parents;

/**
 * @ManyToMany(targetEntity="App_Acl_Role_Abstract", cascade={"persist"})
 * @JoinTable(name="role_children",
 *      joinColumns={@JoinColumn(name="role_id", referencedColumnName="id")},
 *      inverseJoinColumns={@JoinColumn(name="child_id", referencedColumnName="id", unique=true)}
 *      )
 */
private $children;

A role should be able to have many parents and many children

waigani