Reputation: 867
In my Symfony 3 project, I have a ManyToMany relation between "users" and "roles".
It used to work, but now I have an error:
Property AppBundle\Entity\Role::$user does not exist
I don't know what I did, probably it's because of running a "php bin/console doctrine:mapping:import --force AppBundle xml" command.
Here is a fragment of the User entity class:
/**
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
*/
class User implements AdvancedUserInterface, \Serializable {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Role", cascade = {"persist"})
* @ORM\JoinTable(name="user_role")
*/
private $roles;
As you can see there is a relation to the Role entity.
Role entity on the other hand doesn't contain any relation information, and it should work according to this article:
https://knpuniversity.com/screencast/symfony2-ep3/many-to-many-relationship
and it used to work, and now it doesn't and have no idea why.
As far as I understand it, this is named 'unidirectional ManyToMany" relation according to Symfony docs. And for me everything looks fine.
Upvotes: 8
Views: 8379
Reputation: 11253
@Cerad, answer is correct. Just clear the cache (php bin/console cache:clear
) and you should be good to go!
symfony.com/doc/current/console/usage.html
Upvotes: 2
Reputation: 48893
When you ran the mapping command you generated mapping files under AppBundle/Resources/config/doctrine which are interfering with your annotations. In Doctrine you can only have one type of entity mapping per bundle. Multiple types tend to fail silently and confusingly.
This explains why it "used to work".
Delete the config/doctrine directory, maybe clear the cache and you should be back to where you were before.
Upvotes: 8