Your decision made me understand what was going on.
Even if you have entities and annotations, the Doctrine cannot understand the connection between entities. When the doctrine understands the relationship between entities, it knows which methods to call (i.e., User :: getId ()), but otherwise it tries to convert everything you send into a scalar value that it can use to query the database . This is why it calls the __toString function of the user, and therefore, if you return the identifier in toString, everything works from here.
That's fine, but it's a patch, and you probably don't want to store it if we can find a better solution, as it can be harder to maintain as your application grows.
What I see is what in Permissions you have:
/** * @ORM\Column(name="user_id", type="integer") * @ORM\ManyToOne(targetEntity="User", inversedBy="permissions") */ protected $user;
You must remove @ORM\Column(type="integer" )
About join columns, this is optional, but you need to be sure that defauts is what you want. Since we can read here
Before entering all association mappings in detail, you should note that the definitions of @JoinColumn and @JoinTable are usually optional and have reasonable default values. By default, for joining a column in a one-to-one / many-one association:
name: "<fieldname>_id" referencedColumnName: "id"
therefore they will be the same as explicit:
/** * @ORM\ManyToOne(targetEntity="User", inversedBy="permissions", cascade={"persist"}) * @ORM\JoinColumns({ * @ORM\JoinColumn(name="user_id", referencedColumnName="id") * }) */ protected $user;
Thus, it should look up the user_id column in the Permissions table and join it with the id column of the User table. Suppose this is normal.
If this is true, then in your user the identifier should be user_id, but id:
/** * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ protected $id;
Or, if the column name is actually user_id, then the User class is fine, but you need to change the join column to @ORM \ JoinColumn (name = "user_id", referencedColumnName = "user_id")
What can I say. I canβt try, but I will be glad if you can give him a second.