Doctrine ReflectionException property does not exi

2019-03-18 15:55发布

I'm trying to add Doctrine on top of an existing database. I let Doctrine generate annotated entities and adjusted from there. When I try to load the entity below I get the error PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Property Users\\User::$resellerID does not exist'

class User
{
    /* ... */

    /**
     * @var \Doctrine\Common\Collections\Collection
     *
     * @ORM\ManyToOne(targetEntity="\Resellers\Reseller")
     * @ORM\JoinTable(name="reseller",
     *   joinColumns={
     *     @ORM\JoinColumn(name="resellerID", referencedColumnName="resellerID")
     *   },
     *   inverseJoinColumns={
     *     @ORM\JoinColumn(name="resellerID", referencedColumnName="resellerID")
     *   }
     * )
     */
    private $reseller;

    /* ... */
}

Both the user and reseller tables have resellerID columns. My understanding is that for joining ID columns you don't add the ID columns as properties in the entity class. So what's causing the ReflectionException?

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-03-18 16:21

Since I had renamed the autogenerated property from resellerID to reseller (after trying to use it) it turns out I needed to clear the Doctrine cache.

php vendor/bin/doctrine.php orm:clear-cache:result
php vendor/bin/doctrine.php orm:clear-cache:query
php vendor/bin/doctrine.php orm:clear-cache:metadata

Or, if you are using Symfony with Doctrine:

php bin/console doctrine:cache:clear-result
php bin/console doctrine:cache:clear-query
php bin/console doctrine:cache:clear-metadata
查看更多
我想做一个坏孩纸
3楼-- · 2019-03-18 16:34

Usually on production you want something like this:

php bin/console doctrine:cache:clear-result --env=prod

php bin/console doctrine:cache:clear-query --env=prod php bin/console doctrine:cache:clear-metadata --env=prod

查看更多
啃猪蹄的小仙女
4楼-- · 2019-03-18 16:47

For me clearing the PHP APC cache was the solution

<?php
apc_clear_cache();
查看更多
登录 后发表回答