1
Personal I have a relationship of much for one in a table and I need to put the Onupdate in Cascade as I do because I try so of the error:
/**
* @ORM\ManyToOne(targetEntity="JN\Entity\Planos\Plano")
* @ORM\JoinColumn(name="plano_id", referencedColumnName="id", nullable=true, onDelete="SET NULL", onUpdate="CASCADE")
**/
private $plano;
Thank you
John, can you tell me why you want this kind of behavior? Thanks.
– Rodrigo Rigotti
@Rodrigorigotti for the following I always use onUpdate=Cascade, to maintain the integrity of the keys when making a change in a table that by conseguencia has others linked to it. No Doctrine was the first ORM I saw that left the onDelete and disappeared with onUpdate. I’ve always worked like this and I don’t know any other way to maintain data integrity when there are relationships other than this.
– Joao Nivaldo
If you need an onUpdate to maintain referential integrity, it means something in your bank is modeled wrong. You could post an image of your data model in the question?
– Rodrigo Rigotti
@Rodrigorigotti think of a client table and a neighborhood table for example. Client table I have the following columns: ID, Name,id_neighborhood. and In the table neighborhoods I have the columns ID, Neighborhood Name.I have a relationship and 1 neighborhood for several clients. Suppose the center neighborhood is ID 1 today and in a month for some reason it changes to 4. If you have Onupdate you will be changed automatically otherwise only manually. Or is there another way?
– Joao Nivaldo
You want to change the neighborhood id and thereby want the foreign table keys
bairros
on the tableclientes
, that’s it?– Rodrigo Rigotti
This would be one of the simplest examples. But this would be the thought.
– Joao Nivaldo
It is not correct to change the id of a row in a table, since when this id is assigned to a row it cannot be changed. The right thing is, if you want to change a person’s neighborhood, pick it up with the method
findOneBy
ofEntityRepository
and assign it to the user with$user->setBairro($bairro)
.– Rodrigo Rigotti
Okay. I get it. I’ll change then. Thank you very much for the explanation.
– Joao Nivaldo