phpdoctrinedoctrine-odm

Best practice inserting Child in Doctrine without loading parent


I have a database schema which consists of a Parent with n Childs. Now I want to insert a new child without loading the parent, so I dont have to perform an additional DB call. What is the best (most Doctrine like) way to perform such an operation?


Solution

  • DocumentManager::getReference will create an uninitialized proxy object for you. You can use that proxy object freely in your Child class, persist and flush will work normally.