Trying to update one table after inserting into another one with Symfony2 and Doctrine2

后端 未结 1 1874
闹比i
闹比i 2021-01-16 17:54

I wrote a function in BudgetRepository that is called when inserting new data into Budget table. The function is:

public function addBudgetToClie         


        
相关标签:
1条回答
  • 2021-01-16 18:37

    You should not build an update query for this case using a queryBuilder. Use OOP approach to update your entities.

    if ($form->isValid()) {
        $budgetEntity = $form->getData();
        $manager->persist($budgetEntity);
        $clientEntity = $Budget->find($form['client_id']->getData()->getId());
        $clientEntity->setBudget($budgetEntity);
    
        $manager->flush();
        $this->addFlash('success', 'Novo orçamento adicionado');
    
        return $this->redirect($this->generateUrl('panel_budgets'));
    }
    
    0 讨论(0)
提交回复
热议问题