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:
- check if same address exists. if add connection instead of create duplicate address.
- when update jack (from example) , address, add new address instead of updating address of peter.
- 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
Post a Comment