开发者

Zend Framework, Doctrine 2 @ManyToOne

I basicky followed this http://www.zendcasts.com/one-to-many-with-doctrine-2/2011/03/ tutorial to the step (source codes can be downloaded from there). And everything works just fi开发者_运维问答ne, so I got 2 Entities - Purchase and User. If I query User everything is fine, but if I query Purchase, like so:

$entityManager->createQuery('select p from ZC\Entity\Purchase p where p.id = 1')->execute();

I will get an Fatal error:

Fatal error: require() [function.require]: Failed opening required 'C:\xampp\htdocs\CoChces\application/../library/CC/Entity/Proxy\CCEntityCategoryProxy.php' (include_path='C:\xampp\htdocs\CoChces\application/../library;C:\xampp\htdocs\CoChces\library;.;C:\xampp\php\PEAR') in C:\xampp\htdocs\CoChces\library\Doctrine\ORM\Proxy\ProxyFactory.php on line 85

But if i comment this lines in Purchase:

 /**
 *
 * @var User
 * @ManyToOne(targetEntity="User")
 * @JoinColumns({
 *  @JoinColumn(name="user_id", referencedColumnName="id")
 * })
 */
private $user;

Everithing works just fine. So there must be some kind of problem with @ManyToOne annotation. Anyone know what to do with it? Perhaps some workaround?

Thanks a lot for answers..

I'm using PHP 5.3.8


Couple of things...

  1. Your annotation syntax doesn't appear to be correct. Try

    /**
     * @var User
     * @ManyToOne(targetEntity="User")
     */
    private $user;
    

    @JoinColumns doesn't appear anywhere in the documentation. Also, the @JoinColumn annotation is redundant as you are using the default values. See http://www.doctrine-project.org/docs/orm/2.1/en/reference/association-mapping.html#many-to-one-unidirectional

  2. Your DQL query references the ZC namespace root but the error message says CC. Which is correct?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜