Home>

I'm having a little problem submitting resume data to a company. I have three tables in my MySQL database: company, summary and company_summary.

Company table:

Summary table:

Summary_company table:

The following relationships have been configured between tables:

There is a many-to-many relationship between the company and summary tables. That is, a company can have many resume options, and a resume can be sent to N-number of companies. To send candidate resume data to a company, I decided to create a form in which you will need to select a vacancy from the select that was previously created by the user and select the desired company from the select.

Company Model:

<?php
namespace App\Entity;
use App\Repository\CompanyRepository;
use Doctrine\ORM\Mapping as ORM;
/**
 * @ORM\Entity(repositoryClass=CompanyRepository::class)
 */
class Company
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;
    /**
     * @ORM\Column(type="string", length=30)
     */
    private $name;
    /**
     * @ORM\Column(type="string", length=50)
     */
    private $website;
    /**
     * @ORM\Column(type="string", length=100)
     */
    private $address;
    /**
     * @ORM\Column(type="string", length=15)
     */
    private $phone_number;
    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Company", mappedBy="summaries")
     */
    private $companies;
    public function getId(): ?int
    {
        return $this->id;
    }
    public function getName(): ?string
    {
        return $this->name;
    }
    public function setName(?string $name): self
    {
        $this->name= $name;
        return $this;
    }
    public function getWebsite(): ?string
    {
        return $this->website;
    }
    public function setWebsite(?string $website): self
    {
        $this->website= $website;
        return $this;
    }
    public function getAddress(): ?string
    {
        return $this->address;
    }
    public function setAddress(string $address): self
    {
        $this->address= $address;
        return $this;
    }
    public function getPhoneNumber(): ?string
    {
        return $this->phone_number;
    }
    public function setPhoneNumber(string $phone_number): self
    {
        $this->phone_number= $phone_number;
        return $this;
    }
    /**
     * @return Collection|Summary[]
     */
    public function getSummaries(): Collection
    {
        return $this->summary;
    }
    public function addSummary(Summary $summary): self
    {
        if (!$this->summaries->contains($summary)) {
            $this->summaries[]= $summary;
        }
        return $this;
    }
    public function removeSummary(Summary $summary): self
    {
        if ($this->summaries->contains($summary)) {
            $this->summaries->removeElement($summary);
        }
        return $this;
    }
}

Summary:

<?php
namespace App\Entity;
use App\Repository\SummaryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
 * @ORM\Entity(repositoryClass=SummaryRepository::class)
 */
class Summary
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;
    /**
     * @ORM\Column(type="string", length=50)
     */
    private $vacancy;/** * @ORM\Column(type="string", length=1000)
     */
    private $description;
    /**
     * @ORM\Column(type="datetime")
     */
    private $createdAt;
    /**
     * @ORM\Column(type="datetime")
     */
    private $updatedAt;
     /**
     * @ORM\ManyToOne(targetEntity=User::class, inversedBy="summaries")
     * @ORM\JoinColumn(nullable=false)
     */
    private $user;
    /**
     * @ORM\Column(type="boolean")
     */
    private $published;
    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Company", mappedBy="summaries")
     */
    private $companies;
    public function __construct()
    {
        $this->createdAt= new \DateTime();
        $this->updatedAt= new \DateTime();
    }
    public function getId(): ?int
    {
        return $this->id;
    }
    public function getVacancy(): ?string
    {
        return $this->vacancy;
    }
    public function setVacancy(string $vacancy): self
    {
        $this->vacancy= $vacancy;
        return $this;
    }
    public function getDescription(): ?string
    {
        return $this->description;
    }
    public function setDescription(string $description): self
    {
        $this->description= $description;
        return $this;
    }
    public function getCreatedAt(): ?\DateTimeInterface
    {
        return $this->createdAt;
    }
    public function setCreatedAt(\DateTimeInterface $createdAt): self
    {
        $this->createdAt= $createdAt;
        return $this;
    }
    public function getUpdatedAt(): ?\DateTimeInterface
    {
        return $this->updatedAt;
    }
    public function setUpdatedAt(\DateTimeInterface $updatedAt): self
    {
        $this->updatedAt= $updatedAt;
        return $this;
    }
    public function getUser(): ?User
    {
        return $this->user;
    }
    public function setUser(?User $user): self
    {
        $this->user= $user;
        return $this;
    }
    public function getUserId(): ?User
    {
        return $this->user_id;
    }
    public function getPublished(): ?bool
    {
        return $this->published;
    }
    public function setPublished(bool $published): self
    {
        $this->published= $published;
        return $this;
    }
    /*
    * @return Collection|Company[]
    */
   public function getCompanies(): Collection
   {
       return $this->companies;
   }
   public function addCompany(Company $company): self
   {
       if (!$this->companies->contains($company)) {
           $this->companies[]= $company;
           $company->addCompany($this);
       }
       return $this;
   }
   public function removeCompany(Company $company): self
   {
       if ($this->companies->contains($company)) {
           $this->companies->removeElement($company);
           $company->removeCompany($this);
       }
       return $this;
   }
}

SummaryCompany:

<?php
namespace App\Entity;
use App\Repository\SummaryCompanyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
 * @ORM\Entity(repositoryClass=SummaryCompanyRepository::class)
 */
class SummaryCompany
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;
     /**
     * @ORM\Column(type="datetime")
     */
    private $receivedAt;
    /**
     * @varint
     *
     * @ORM\Column(name="summary_id", type="integer")
     */
    private $summaryId;
    /**
     * @varint
     *
     * @ORM\Column(name="company_id", type="integer")
     */
    private $companyId;
    public function __construct()
    {
        //$this->summaries= new ArrayCollection();
        //$this->companies= new ArrayCollection();
        $this->receivedAt= new \DateTime();
    }
    public function getCompanies(): Collection
    {
        return $this->companies;
    }
    public function getSummaries(): Collection
    {
        return $this->summary; }
    public function getId(): ?int
    {
        return $this->id;
    }
    public function getReceivedAt(): ?\DateTimeInterface
    {
        return $this->receivedAt;
    }
    public function setReceivedAt(\DateTimeInterface $receivedAt): self
    {
        $this->receivedAt= $receivedAt;
        return $this;
    }
    /**
     * Set summaryId
     *
     * @param integer $summaryId
     *
     *@returncompany
     */
    public function setSummaryId($summaryId)
    {
        $this->summaryId= $summaryId;
        return $this;
    }
    /**
     * Get summaryId
     *
     * @return int
     */
    public function getSummaryId()
    {
        return $this->summaryId;
    }
    /**
     * Set companyId
     *
     * @param integer $companyId
     *
     * @return Summary
     */
    public function setCompanyId($companyId)
    {
        $this->companyId= $companyId;
        return $this;
    }
    /**
     * Get companyId
     *
     * @return int
     */
    public function getCompanyId()
    {
        return $this->companyId;
    }
}

SummaryController:

/**
     * @Route("/send_summary", name="send_summary", methods={"GET","POST"})
     * @param Request $request
     * @return Response
     */
    public function send_summary(Request $request): Response
    {
        $summaryCompany= new SummaryCompany();
        $form= $this->createForm(SummaryCompanyType::class, $summaryCompany);
        $form->handleRequest($request);
        $entityManager= $this->getDoctrine()->getManager();
        if ($form->isSubmitted() &
&
 $form->isValid()) {
            $entityManager->persist($summaryCompany);
            //dd($summaryCompany);
            $entityManager->flush();
            $this->addFlash('success', 'Resume successfully submitted!');
            return $this->redirectToRoute('summary.index');
        }
        return $this->render('summary/send_summary.html.twig', [
            //'summaryCompany'=> $summaryCompany,
            'form'=> $form->createView(),
        ]);
    }

SummaryCompanyType.php

<?php
namespace App\Form;
use App\Entity\SummaryCompany;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SummaryCompanyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
       $builder
            ->add('summaryId', EntityType::class, [
                'class'=> summary::class,
                'multiple'=> true,
                'choice_label'=> function ($summary) {
                    return $summary->getVacancy();
            }])
            ->add('companyId', EntityType::class, [
                'class'=> company::class,
                'multiple'=> true,
                'choice_label'=> function ($company) {
                    return $company->getName();
            }])
        ;
    }
    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefault([
            'data_class'=> SummaryCompany::class,
        ]);
    }
}

_receive_form.html.twig

{{ form_start(form) }}
    {{ form_row(form.summaryId, {
        label: 'Posada'
    }) }}
    {{ form_row(form.companyId, {
        label: 'Companies'
    }) }}
    <button class="btn btn-success"><i class='fas fa-plus-square'></i> Save</button>    <a class="btn btn-primary" href="{{ path('summary.index') }}"><i class='fas fa-briefcase'></i> Resume List</a>{{ form_end(form)}}

This is how the form for submitting a resume to a company looks like:

After submitting data, the following error occurs:

What is the specific problem here? "There's something missing" -how do you understand that something is missing?

u_mulder2022-01-22 15:36:13

while I figure it out

Magic Fox2022-01-22 15:36:13