1
resposta

SQLSTATE[42P01]: Undefined table:

Prezados,

Sou iniciante no PHP e Symfony, e estou experimentando o erro abaixo. Achei alguns tópicos no fórum, porém não obtive sucesso na resolução.

"An exception occurred while executing a query: SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "t0" LINE 1: ...de_batismo_integrante_14 FROM integrante t1 WHERE t0.id = $1 ^"

A regra de negócio é simples: Ao criar um cargo(Presidente/Vice-Presidente/Diretor) na tabela ELEITOS é preciso associá-lo a um INTEGRANTE. A entidade INTEGRANTE estende da entidade MOTOCICLISTA.

ENTIDADE ELEITOS

<?php

namespace App\Entity;

use JsonSerializable; use Doctrine\ORM\Mapping as ORM; use App\Repository\EleitosRepository;

#[ORM\Entity(repositoryClass: EleitosRepository::class)] class Eleitos implements JsonSerializable {

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;

#[ORM\Column(type: 'string', length: 100, nullable: true)]
private $cargo;

#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $descricao;

#[ORM\ManyToOne(targetEntity: Integrante::class, inversedBy: 'eleitos')]
private $nomeado;

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

public function getCargo(): ?string
{
    return $this->cargo;
}

public function setCargo(?string $cargo): self
{
    $this->cargo = $cargo;

    return $this;
}

public function getDescricao(): ?string
{
    return $this->descricao;
}

public function setDescricao(?string $descricao): self
{
    $this->descricao = $descricao;

    return $this;
}

public function getNomeado(): ?Integrante
{
    return $this->nomeado;
}

public function setNomeado(?Integrante $nomeado): self
{
    $this->nomeado = $nomeado;

    return $this;
}

public function JsonSerialize()
{
    return
    [
        'id' => $this->getId(),
        'cargo' => $this->getCargo(),
        'descricao' => $this->getDescricao(),
        'integranteNomeado' =>$this->getNomeado()->getId()

    ];
}

}

CLASSE INTEGRANTE

<?php

namespace App\Entity;

use App\Entity\Motociclista; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use App\Repository\IntegranteRepository; use JsonSerializable;

#[ORM\Entity(repositoryClass: IntegranteRepository::class)] class Integrante extends Motociclista implements \JsonSerializable {

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
protected $id;

#[ORM\Column(type: 'date')]
protected $dataDeBatismoIntegrante;

#[ORM\OneToMany(mappedBy: 'nomeado', targetEntity: Eleitos::class)]
private $eleitos;

public function __construct()
{
    parent::__construct();
    $this->Nomeado = new ArrayCollection();
    $this->eleitos = new ArrayCollection();
}

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

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

public function setDataDeBatismoIntegrante(\DateTimeInterface $dataDeBatismoIntegrante): self
{
    $this->dataDeBatismoIntegrante = $dataDeBatismoIntegrante;

    return $this;
}

/**
 * @return Collection<int, Eleitos>
 */
public function getEleitos(): Collection
{
    return $this->eleitos;
}

public function addEleito(Eleitos $eleito): self
{
    if (!$this->eleitos->contains($eleito)) {
        $this->eleitos[] = $eleito;
        $eleito->setNomeado($this);
    }

    return $this;
}

public function removeEleito(Eleitos $eleito): self
{
    if ($this->eleitos->removeElement($eleito)) {
        // set the owning side to null (unless already changed)
        if ($eleito->getNomeado() === $this) {
            $eleito->setNomeado(null);
        }
    }

    return $this;
}

public function JsonSerialize()
{
    return 
    [
        'id' => $this->getId(),
        'datadebatismointegrante' => $this->getDataDeBatismoIntegrante(),
        'eleitos' => $this->getEleitos()
    ];
}

}

1 resposta

Oi Cláudio, tudo bem? Espero que sim!

Primeiramente, peço desculpas pela demora em te dar um retorno.

Você está enfrentando um erro porque o programa está tentando conectar um cargo da tabela "Eleitos" com um integrante da tabela "Integrante" usando uma consulta SQL. No entanto, parece que a tabela "Integrante" não está sendo reconhecida corretamente nessa consulta, o que está causando o problema.

Para corrigir, você pode dar uma olhadinha na nomenclatura da tabela no banco de dados e verificar se a tabela "Integrante" existe e que seu nome está correto. O nome da tabela no código (entidade) deve corresponder ao nome da tabela no banco de dados.

Você também pode verificar o mapeamento de entidades, se certificando de que as anotações de mapeamento entre as entidades "Eleitos" e "Integrante" estão corretas. Especificamente, verifique se a anotação @ORM\ManyToOne na classe "Eleitos" aponta corretamente para a classe "Integrante" e se o nome da propriedade está correto ("nomeado").

Espero ter ajudado!

Caso tenha dúvidas, fico à disposição.

Abraços e bons estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software