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 the ID (112).
I'm sure I did not write any code to duplicate the records in the database - I've just read out them (Select) without any writing operations like Insert or Update.
Could anyone tell me, why this happened? I am so confused!
Thanks a lot.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.