read objects persisted but not yet flushed with doctrine

前端 未结 3 736
慢半拍i
慢半拍i 2021-01-03 22:57

I\'m new to symfony2 and doctrine. here is the problem as I see it. i cannot use :

$repository = $this->getDoctrine()->getRepository(\         


        
3条回答
  •  梦谈多话
    2021-01-03 23:46

    Your is a business logic problem effectively.

    Querying down the Database a findby Query on Object that are not flushed yet, means heaving much more the DB layer querying object that you have already in your function scope.

    Also Keep in mind a findOneBy will retrieve also other object previously saved with same features.

    If you need to find only among those new created objects, you should make f.e. them in a Session Array Variable, and iterate them with the foreach.

    If you need a mix of already saved items + some new items, you should threate the 2 parts separately, one with a foreach , other one with the repository query!

提交回复
热议问题