symfony - manyToMany connection add existing entity or create a new one -


imagine connection person x address (manytomany). user wants add person same address, has previous person.

 person address              address                        +------------------------+  +-------------------------------+ | person_id | address_id |  | id | postcode | city     |... | +------------------------+  +-------------------------------+ | 1         | 1          |  | 1  | 15800    | new york |... | | 2         | 1          |  | 2  | 25385    | london   |... | +------------------------+  +-------------------------------+   person +------------------+ | id | name  | ... | +------------------+ | 1  | jack  | ... | | 2  | peter | ... | +------------------+ 

is there automatic way to:

  1. check if same address exists. if add connection instead of create duplicate address.
  2. when update jack (from example) , address, add new address instead of updating address of peter.
  3. when delete check if there address connected person. if not delete address, otherwise delete connection.

in case it's quite easy check before changes persisted db, in more complex example it's annoying when have check 3 records in same moment in addition connected.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -