What is the difference between inversedBy and mappedBy?

后端 未结 4 1925
[愿得一人]
[愿得一人] 2020-12-04 05:26

I am developing my application using Zend Framework 2 and Doctrine 2.

While writting annotations, I am unable to understand the difference between mappedBy

4条回答
  •  失恋的感觉
    2020-12-04 06:16

    5.9.1. Owning and Inverse Side

    For Many-To-Many associations you can chose which entity is the owning and which the inverse side. There is a very simple semantic rule to decide which side is more suitable to be the owning side from a developers perspective. You only have to ask yourself, which entity is responsible for the connection management and pick that as the owning side.

    Take an example of two entities Article and Tag. Whenever you want to connect an Article to a Tag and vice-versa, it is mostly the Article that is responsible for this relation. Whenever you add a new article, you want to connect it with existing or new tags. Your create Article form will probably support this notion and allow to specify the tags directly. This is why you should pick the Article as owning side, as it makes the code more understandable:

    http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html

提交回复
热议问题