Symfony cmd error "Целевая сущность .. не может быть найдена в .." - PullRequest
0 голосов
/ 16 февраля 2020

Я начинаю с Symfony Framework и пытаюсь установить отношения ManyToMany. Но когда я пробую эту командную строку

php bin/console doctrine:schema:update

, я получаю эту ошибку:

The target-entity C:\xampp\htdocs\symfony-tp\src\Entity\Competetence cannot be found in 'App\Entity\Stagiaire#competencies'.

Stagiaire. php

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\StagiaireRepository")
 */
class Stagiaire
{
    /**
     * @ORM\ManyToMany(targetEntity="C:\xampp\htdocs\symfony-tp\src\Entity\Competetence",cascade={"persist"})
     */
    private $competencies;

    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="datetime")
     */
    private $createdAt;

    /**
     * @ORM\Column(type="string", length=50)
     */
    private $name;

    /**
     * @ORM\Column(type="integer")
     */
    private $phone;

    /**
     * @ORM\Column(type="datetime")
     */
    private $birthday;
    /**
     * @var \Datetime
     */
    private $date;

    public function __construct()
    {
        $this->date = new \Datetime();
        $this->competencies = new ArrayCollection();
    }

    public function addCompetence(Competence $competence)
    {
        $this->$competence[] = $competence;

        return $this;
    }

    public function removeCompetence(Competence $competence)
    {
        $this->competencies->removeElement($competence);
    }

    public function getCompetencies()
    {
        return $this->competencies;
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getCreatedAt(): ?\DateTimeInterface
    {
        return $this->createdAt;
    }

    public function setCreatedAt(\DateTimeInterface $createdAt): self
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getPhone(): ?int
    {
        return $this->phone;
    }

    public function setPhone(int $phone): self
    {
        $this->phone = $phone;

        return $this;
    }

    public function getBirthday(): ?\DateTimeInterface
    {
        return $this->birthday;
    }

    public function setBirthday(\DateTimeInterface $birthday): self
    {
        $this->birthday = $birthday;

        return $this;
    }
}

Компетентность. php

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity(repositoryClass="App\Repository\CompetenceRepository")
 */
class Competence
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=50)
     */
    private $name;

    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;
    }
}

Спасибо за помощь!

1 Ответ

2 голосов
/ 16 февраля 2020

В аннотации Stagiaire::$competencies необходимо указать полное имя класса Competence вместо пути к файлу на вашем компьютере, и это будет App\Entity\Competence

Так вот:

    /**
     * @ORM\ManyToMany(targetEntity="C:\xampp\htdocs\symfony-tp\src\Entity\Competetence",cascade={"persist"})
     */
    private $competencies;

Становится:

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Competence",cascade={"persist"})
     */
    private $competencies;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...