I want to load all Stagiaires to be paid in Bordereaus. I want to select only those internships that ended within the date interval by selecting the date intervals and passing the intern's attributes through them.
"Interns" and "Payment" are not related, but there is a table "Interns_Payment" (Bordereau_stagiaire) that links to both tables. I want to do this via a repository and then load it into my PaymentController's Edit. I'm new to symfnony
I wrote this query in my Payment(Bordereau)Repository
public function findByDate(Bordereau $bordereau){ $query = $this->createQueryBuilder('bo'); return $query->select('bo', 'bord_stag', 'st') ->leftJoin('bo.bordereauStagiaire', 'bord_stag') ->leftJoin('bord_stag.stagiaire', 'st') ->andWhere('st.finStage >= IN(:dateDebut)') ->andWhere('st.finStage <= IN(:dateFin)') ->andWhere('st.isDeleted = IN(:delete)') ->setParameter('delete', false) ->setParameter('dateFin', $bordereau->dateFin) ->setParameter('dateDebut', $bordereau->dateDebut) ->getQuery() ->getResult() ; }
This is the payment (Bordereau) editing function in my controller
#[Route('/{id}/edit', name: 'app_bordereau_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Bordereau $bordereau, BordereauRepository $bordereauRepo): Response { $formBordereau = $this->createForm(BordereauEditType::class, $bordereau); $formBordereau->handleRequest($request); if ($formBordereau->isSubmitted() && $formBordereau->isValid()) { $bordereauRepo->save($bordereau, true); dd($bordereau); return $this->redirectToRoute('app_bordereau_index', [], Response::HTTP_SEE_OTHER); } return $this->renderForm('bordereau/edit.html.twig', [ 'bordereau' => $bordereau, 'form' => $formBordereau, ]); }
I was hoping to get the result by checking dd($bordereauRepository);
but instead I get this result.
I searched for similar issues regarding "Too few parameters in query" but was unsuccessful in finding a solution.
Edit
I added setParamaters for dateDebut and dateFin. But I can't access it.
Should I create a custom form of bordereau?
Edit 2
This is my new DQL function
public function findByDate(BordereauEditModel $bordereau, bool $isDeleted = false){ $query = $this->createQueryBuilder('bo'); $query ->select('bo', 'bord_stag', 'st') ->leftJoin('bo.bordereauStagiaire', 'bord_stag') ->leftJoin('bord_stag.stagiaire', 'st') ->andWhere('st.isDeleted = :delete') ->setParameter('delete', $isDeleted); if ($bordereau->dateDebut) { $query->andWhere('st.finStage <= :dateDebut') ->setParameter('dateDebut', $bordereau->dateDebut->format('Y-m-d')); } if ($bordereau->dateFin) { $query->andWhere('st.finStage <= :dateFin') ->setParameter('dateFin', $bordereau->dateFin->format('Y-m-d')); } $query ->getQuery() ->getResult() ; }
It prints the results using the static parameters I set. But not for dynamic ones.
I also created a model BordereauEditModel
and a custom form
BordereauEditType
This is my edit
function
BordereauController
#[Route('/{id}/edit', name: 'app_bordereau_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Bordereau $bordereau, BordereauRepository $bordereauRepository, BordereauEditModel $bordereauEdit): Response { $bordereauEdit = new BordereauEditModel(); $formBordereau = $this->createForm(BordereauEditType::class, $bordereauEdit); $formBordereau->handleRequest($request); if ($formBordereau->isSubmitted() && $formBordereau->isValid()) { $bordereauRepository->findByDate($bordereauEdit); $bordereauRepository->save($bordereau, true); dd($bordereauRepository); return $this->redirectToRoute('app_bordereau_index', [], Response::HTTP_SEE_OTHER); } return $this->renderForm('bordereau/edit.html.twig', [ 'bordereau' => $bordereau, 'form' => $formBordereau, ]); }
When I try to load dynamic it says "Call member function format() on null". I don't know if this is another question and I should remove it from here (i.e. as a paragraph in the main post so people don't get confused)
Call member function format() on null -> Solved
Remove
IN
from the condition. If you want to check usingIN
, you cannot use comparison operators.