Symfony Doctrine: records added to table unexpectedly
In my Symfony code I've used Doctrine. In an Entity ( AppBundleEntityCoreUser ) I defined a column foodTypes , which is associated with another Entity (AppBundleEntityFoodRecordingFoodType). I've defined an Many-to-Many relationship between User and FoodType , with a linking table foodrecording_user , joining User.username and FoodType.foodtype_code . The code is shown below. As expected, I can fetch foodTypes of a certain user, and everything seems like good, until I occasionally found out that ... everytime I run the application, it seems like that the program unexpectedly adds new records in the table foodrecording_user , for instance, if the original contents in this table are: Then, after running the application with the user named 30001180, the contents will turn to be something like: Here the 112 is the ID (primary key) of the user (with username 30001180). That means, the program seems to duplicate the records of the user, just replacing the username (30001180) with ...