Please, could anybody explain with examples idea of “owning side” and “inverse side” concepts in Doctrine? I understand that they are necessary to organize bidirectional relationship, but I can’t realize following text from Doctrine documentation (link):
There are 2 references on each side of the association and these 2 references both represent the same association but can change independently of one another.
- Why there are 2 references on each side, and in total 4? Now, in total, I see only 2 references From A (owning side) to B (inverse side), and from B to A.
- In which situations references can be changed independently of one another?
- What happens in memory that trigger necessity of “owning side ” and “ inverse side usage?
- What is difference between “reference” and “association”?
Edit
For example, I have entities Customer (owning side) and Company (inverse side). At first, I do following:
$customer = new Customer();
$company = new Company();
$customer->setCompany($company);
$company->setCustomer($customer);
Then I can have two scenarios:
Scenario 1
$company->getCustomer()->setName(‘John’);
$entityManager->persist($company);
$entityManager->flush();
Scenario 2
$customer->getCompany()->setLicenseNumber(‘24535’);
$entityManager->persist($company);
$entityManager->flush();
Do I understand rightly, that in first case association will be persisted correctly, because owning side (through getCustomer()) is changed, but in second case it will be ignored, because owning side is not changed?