我正在尝试在 Doctrine 2 中实现一对一的自引用关系。所以,我的实体 Membro_model 是:
<?php
/**
*
* @Entity
* @Table(name="tb_membro")
*/
class Membro_model
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="IDENTITY")
*/
public $id = 0;
/**
* @Column(type="string", columnDefinition="VARCHAR(50) NOT NULL")
*/
public $nome = 0;
/**
* @Column(type="string", columnDefinition="VARCHAR(50) NOT NULL")
*/
public $email = 0;
/**
* @Column(type="string", columnDefinition="VARCHAR(12) NOT NULL")
*/
public $login = 0;
/**
* @OneToOne(targetEntity="Membro_model")
* @JoinColumn(name="patrocinador_id", referencedColumnName="id")
**/
public $patrocinador;
}
我可以持久化实体。我在恢复数据时遇到问题。当字段 patrocinador_id 为 NULL 时,我恢复没有问题,但是当字段不为 NULL 时,出现以下错误:
Fatal error: require(): Failed opening required
'application//models/proxies\__CG__Membro_model.php'
(include_path='.;C:\php\pear') in C:\Program Files\EasyPHP-DevServer-
13.1VC9\data\localweb\eliteapp\application\third_party\DoctrineORM-
2.2.2\libraries\Doctrine\ORM\Proxy\ProxyFactory.php on line 93
我正在尝试使用 findOneBy 进行恢复:
$membro = $this->doctrine->em->getRepository('Membro_model')->findOneBy(array('login' => $login));