26

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?

7 Answers 7

68

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 
Sign up to request clarification or add additional context in comments.

4 Comments

What if none of the given answers works ? I 've using Symfony since 2014 and never had such issue until I start to use 'json' and 'json_array' types in an entity .
@DiegoFavero I would open a new question specific to your scenario. Link back to this one so you don't get flagged as a duplicate. I've never used those types in an entity so maybe there's something special that needs to be done.
Paid a bit of research, and I think I will open an issue ticket on Doctrine's page because I did not find any similar problem !
to run all these commands with the same order in the answer is really important btw.
3

For me clearing the PHP APC cache was the solution

<?php apc_clear_cache(); 

2 Comments

This was what I needed in the end - clearing the doctrine cache turned out to be a temporary measure and it was only when I restarted memcached that I got rid of the error for good.
Same idea if using opcache with the opcache.validate_timestamps = false flag. Clear the cache by restarting the web server. Thanks @michalzuber for the idea!
1

Anyway, it helped me

php artisan doctrine:clear:metadata:cache 

Comments

0

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 

Comments

0

My error still occurred when I attempted to clear the doctrine cache.

What worked for me was to manually clear the cache by deleting the folder under /storage/framework/cache/*

Comments

0

In Symfony, due to Docker container permissions, I had to manually delete everything under /var/cache/.

Comments

0

If anyone is reading this while using a Docker container:

  1. Use Terminal within your PHP/Symfony container.
  2. Enter the doctrine cache clear commands referenced in older answers:
 php bin/console doctrine:cache:clear-result php bin/console doctrine:cache:clear-query php bin/console doctrine:cache:clear-metadata 
  1. Do the APC cache clear also referenced in older answers:
 php -r "apc_clear_cache();" 
  1. Restart your PHP / Symfony container in Docker.

The restart as a last step ends up clearing whatever is lingering, at least in my case. Hope this helps anyone else using Docker.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.