Doctrine で Symfony2 を使用していますが、コントローラーからクエリを実行すると、次のエラーが表示されます (ページを呼び出すとナビゲーターに表示されます)。
Entity class 'Bdreamers\SuenoBundle\Entity\Sueno_video' used in the discriminator map of class 'Bdreamers\SuenoBundle\Entity\Sueno' does not exist.
「Sueno」と呼ばれる 1 つのエンティティ (スーパークラス) と、それから拡張された 2 つのエンティティ (サブクラス): Sueno_foto と Sueno_video があります。
フィクスチャをロードすると、Doctrine は完璧に動作し、問題なくデータベースを埋め、"Sueno" テーブルの識別子フィールド "tipo" を正しく埋めます。また、「Sueno」の ID と「Sueno_video」の専用フィールドを導入する継承されたエンティティ テーブル「Sueno_video」を正しく入力します。
これは、「Sueno」のエンティティ ファイルのコードです。
<?php
namespace Bdreamers\SuenoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table()
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="tipo", type="string")
* @ORM\DiscriminatorMap({"sueno" = "Sueno", "video" = "Sueno_video", "foto" = "Sueno_foto"})
*/
class Sueno
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Bdreamers\UsuarioBundle\Entity\Usuario")
**/
private $usuario;
/**
* @ORM\ManyToMany(targetEntity="Bdreamers\SuenoBundle\Entity\Tag", inversedBy="suenos")
* @ORM\JoinTable(name="suenos_tags")
**/
private $tags;
/**
* @ORM\ManyToMany(targetEntity="Bdreamers\UsuarioBundle\Entity\Usuario", mappedBy="suenos_sigue")
* @ORM\JoinTable(name="usuarios_siguen")
**/
private $usuariosSeguidores;
/**
* @ORM\ManyToMany(targetEntity="Bdreamers\UsuarioBundle\Entity\Usuario", mappedBy="suenos_colabora")
* @ORM\JoinTable(name="usuarios_colaboran")
**/
private $usuariosColaboradores;
/**
* @var \DateTime
*
* @ORM\Column(name="fecha_subida", type="datetime")
*/
private $fechaSubida;
/**
* @var string
*
* @ORM\Column(name="titulo", type="string", length=40)
*/
private $titulo;
/**
* @var string
*
* @ORM\Column(name="que_pido", type="string", length=140)
*/
private $quePido;
/**
* @var string
*
* @ORM\Column(name="texto", type="string", length=540)
*/
private $texto;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set usuario
*
* @param string $usuario
* @return Sueno
*/
public function setUsuario($usuario)
{
$this->usuario = $usuario;
return $this;
}
/**
* Get usuario
*
* @return string
*/
public function getUsuario()
{
return $this->usuario;
}
public function getTags()
{
return $this->tags;
}
/**
* Set usuariosSeguidores
*
* @param string $usuariosSeguidores
* @return Sueno
*/
public function setUsuariosSeguidores($usuariosSeguidores)
{
$this->usuariosSeguidores = $usuariosSeguidores;
return $this;
}
/**
* Get usuariosSeguidores
*
* @return string
*/
public function getUsuariosSeguidores()
{
return $this->usuariosSeguidores;
}
/**
* Set usuariosColaboradores
*
* @param string $usuariosColaboradores
* @return Sueno
*/
public function setUsuariosColaboradores($usuariosColaboradores)
{
$this->usuariosColaboradores = $usuariosColaboradores;
return $this;
}
/**
* Get usuariosColaboradores
*
* @return string
*/
public function getUsuariosColaboradores()
{
return $this->usuariosColaboradores;
}
/**
* Set fechaSubida
*
* @param \DateTime $fechaSubida
* @return Sueno
*/
public function setFechaSubida($fechaSubida)
{
$this->fechaSubida = $fechaSubida;
return $this;
}
/**
* Get fechaSubida
*
* @return \DateTime
*/
public function getFechaSubida()
{
return $this->fechaSubida;
}
/**
* Set titulo
*
* @param string $titulo
* @return Sueno
*/
public function setTitulo($titulo)
{
$this->titulo = $titulo;
return $this;
}
/**
* Get titulo
*
* @return string
*/
public function getTitulo()
{
return $this->titulo;
}
/**
* Set quePido
*
* @param string $quePido
* @return Sueno
*/
public function setQuePido($quePido)
{
$this->quePido = $quePido;
return $this;
}
/**
* Get quePido
*
* @return string
*/
public function getQuePido()
{
return $this->quePido;
}
/**
* Set texto
*
* @param string $texto
* @return Sueno
*/
public function setTexto($texto)
{
$this->texto = $texto;
return $this;
}
/**
* Get texto
*
* @return string
*/
public function getTexto()
{
return $this->texto;
}
public function __construct() {
$this->usuariosColaboradores = new \Doctrine\Common\Collections\ArrayCollection();
$this->usuariosSeguidores = new \Doctrine\Common\Collections\ArrayCollection();
$this->tags = new \Doctrine\Common\Collections\ArrayCollection();
}
public function __toString()
{
return $this->getTitulo();
}
}
これは、エンティティ Sueno_video のコードです。
<?php
namespace Bdreamers\SuenoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table()
* @ORM\Entity
*/
class Sueno_video extends Sueno
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="link_video", type="string", length=255)
*/
private $linkVideo;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set linkVideo
*
* @param string $linkVideo
* @return Sueno_video
*/
public function setLinkVideo($linkVideo)
{
$this->linkVideo = $linkVideo;
return $this;
}
/**
* Get linkVideo
*
* @return string
*/
public function getLinkVideo()
{
return $this->linkVideo;
}
}
そして最後にコントローラーのコード:
public function homeAction()
{
$em = $this->getDoctrine()->getManager();
$suenos = $em->getRepository('SuenoBundle:Sueno')->findOneBy(array(
'fechaSubida' => new \DateTime('now -2 days')
));
return $this->render('EstructuraBundle:Home:home_registrado.html.twig');
}