2

我正在尝试遵循此页面上教义文档的建议- 使用 ArrayCollection 初始化一个类成员。对于文档中给出的示例,一切都很好。我正在尝试使用继承的类来执行此操作,但收到错误消息:

Class Doctrine\Common\Collections\ArrayCollection is not a valid entity or mapped super 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();
}

}

继承类:

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

当我将构造函数移动到继承类时,一切正常。但是将它们放在继承的抽象类中会更整洁。为什么它不起作用?可能吗?

4

1 回答 1

0

我的错。我塞满了映射。这是我现在使用的映射:

/**
 * @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;

一个角色应该可以有很多父母和很多孩子

于 2010-09-10T00:44:42.863 回答