Zend 2 + Doctrine 实体请求

Zend 2 + Doctrine Entity request

我在使用学说时遇到问题。当我尝试获取特定实体时,无法检索结果。 我有这些实体:

<?php

namespace TDS\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Courses
 *
 * @ORM\Table(name="courses")
 * @ORM\Entity
 */
class Courses
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=64, nullable=false)
     */
    private $name;



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     *
     * @return Courses
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
}

<?php

namespace TDS\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Levels
 *
 * @ORM\Table(name="levels")
 * @ORM\Entity
 */
class Levels
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=64, nullable=false)
     */
    private $name;



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     *
     * @return Levels
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
}

<?php

namespace TDS\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Places
 *
 * @ORM\Table(name="places")
 * @ORM\Entity
 */
class Places
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=64, nullable=false)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="address", type="text", length=65535, nullable=false)
     */
    private $address;

    /**
     * @var float
     *
     * @ORM\Column(name="latitude", type="float", precision=10, scale=0, nullable=false)
     */
    private $latitude;

    /**
     * @var float
     *
     * @ORM\Column(name="longitude", type="float", precision=10, scale=0, nullable=false)
     */
    private $longitude;



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     *
     * @return Places
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set address
     *
     * @param string $address
     *
     * @return Places
     */
    public function setAddress($address)
    {
        $this->address = $address;

        return $this;
    }

    /**
     * Get address
     *
     * @return string
     */
    public function getAddress()
    {
        return $this->address;
    }

    /**
     * Set latitude
     *
     * @param float $latitude
     *
     * @return Places
     */
    public function setLatitude($latitude)
    {
        $this->latitude = $latitude;

        return $this;
    }

    /**
     * Get latitude
     *
     * @return float
     */
    public function getLatitude()
    {
        return $this->latitude;
    }

    /**
     * Set longitude
     *
     * @param float $longitude
     *
     * @return Places
     */
    public function setLongitude($longitude)
    {
        $this->longitude = $longitude;

        return $this;
    }

    /**
     * Get longitude
     *
     * @return float
     */
    public function getLongitude()
    {
        return $this->longitude;
    }
}

<?php

namespace TDS\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * TimeSlot
 *
 * @ORM\Table(name="time_slot")
 * @ORM\Entity
 */
class TimeSlot
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="start", type="time", nullable=false)
     */
    private $start;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="end", type="time", nullable=false)
     */
    private $end;

    /**
     * @var integer
     *
     * @ORM\Column(name="day", type="integer", nullable=false)
     */
    private $day;



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set start
     *
     * @param \DateTime $start
     *
     * @return TimeSlot
     */
    public function setStart($start)
    {
        $this->start = $start;

        return $this;
    }

    /**
     * Get start
     *
     * @return \DateTime
     */
    public function getStart()
    {
        return $this->start;
    }

    /**
     * Set end
     *
     * @param \DateTime $end
     *
     * @return TimeSlot
     */
    public function setEnd($end)
    {
        $this->end = $end;

        return $this;
    }

    /**
     * Get end
     *
     * @return \DateTime
     */
    public function getEnd()
    {
        return $this->end;
    }

    /**
     * Set day
     *
     * @param integer $day
     *
     * @return TimeSlot
     */
    public function setDay($day)
    {
        $this->day = $day;

        return $this;
    }

    /**
     * Get day
     *
     * @return integer
     */
    public function getDay()
    {
        return $this->day;
    }
}

这些实体使用 table 连接起来。此 table 还包含一个 id,因为一行可以被另一个 table.

引用

这是最后一个实体:

<?php

namespace TDS\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * CoursesLevelsPlaces
 *
 * @ORM\Table(name="courses_levels_places", uniqueConstraints={@ORM\UniqueConstraint(name="id_course", columns={"id_course", "id_level", "id_place", "id_time_slot"})}, indexes={@ORM\Index(name="courses", columns={"id_course"}), @ORM\Index(name="levels", columns={"id_level"}), @ORM\Index(name="places", columns={"id_place"}), @ORM\Index(name="time_slot", columns={"id_time_slot"})})
 * @ORM\Entity
 */
class CoursesLevelsPlaces
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \TDS\Entity\Courses
     *
     * @ORM\ManyToOne(targetEntity="TDS\Entity\Courses")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_course", referencedColumnName="id")
     * })
     */
    private $idCourse;

    /**
     * @var \TDS\Entity\Levels
     *
     * @ORM\ManyToOne(targetEntity="TDS\Entity\Levels")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_level", referencedColumnName="id")
     * })
     */
    private $idLevel;

    /**
     * @var \TDS\Entity\Places
     *
     * @ORM\ManyToOne(targetEntity="TDS\Entity\Places")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_place", referencedColumnName="id")
     * })
     */
    private $idPlace;

    /**
     * @var \TDS\Entity\TimeSlot
     *
     * @ORM\ManyToOne(targetEntity="TDS\Entity\TimeSlot")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_time_slot", referencedColumnName="id")
     * })
     */
    private $idTimeSlot;



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set idCourse
     *
     * @param \TDS\Entity\Courses $idCourse
     *
     * @return CoursesLevelsPlaces
     */
    public function setIdCourse(\TDS\Entity\Courses $idCourse = null)
    {
        $this->idCourse = $idCourse;

        return $this;
    }

    /**
     * Get idCourse
     *
     * @return \TDS\Entity\Courses
     */
    public function getIdCourse()
    {
        return $this->idCourse;
    }

    /**
     * Set idLevel
     *
     * @param \TDS\Entity\Levels $idLevel
     *
     * @return CoursesLevelsPlaces
     */
    public function setIdLevel(\TDS\Entity\Levels $idLevel = null)
    {
        $this->idLevel = $idLevel;

        return $this;
    }

    /**
     * Get idLevel
     *
     * @return \TDS\Entity\Levels
     */
    public function getIdLevel()
    {
        return $this->idLevel;
    }

    /**
     * Set idPlace
     *
     * @param \TDS\Entity\Places $idPlace
     *
     * @return CoursesLevelsPlaces
     */
    public function setIdPlace(\TDS\Entity\Places $idPlace = null)
    {
        $this->idPlace = $idPlace;

        return $this;
    }

    /**
     * Get idPlace
     *
     * @return \TDS\Entity\Places
     */
    public function getIdPlace()
    {
        return $this->idPlace;
    }

    /**
     * Set idTimeSlot
     *
     * @param \TDS\Entity\TimeSlot $idTimeSlot
     *
     * @return CoursesLevelsPlaces
     */
    public function setIdTimeSlot(\TDS\Entity\TimeSlot $idTimeSlot = null)
    {
        $this->idTimeSlot = $idTimeSlot;

        return $this;
    }

    /**
     * Get idTimeSlot
     *
     * @return \TDS\Entity\TimeSlot
     */
    public function getIdTimeSlot()
    {
        return $this->idTimeSlot;
    }
}

当我进行查询以获取所有 CoursesLevelsPlaces 时,请求运行了很长时间然后中断。尝试生成 print_r 结果:

Array ( [0] => TDS\Entity\CoursesLevelsPlaces Object ( [id:TDS\Entity\CoursesLevelsPlaces:private] => 1 [idCourse:TDS\Entity\CoursesLevelsPlaces:private] => DoctrineORMModule\Proxy\__CG__\TDS\Entity\Courses Object ( [__initializer__] => Closure Object ( [static] => Array ( [entityPersister] => Doctrine\ORM\Persisters\Entity\BasicEntityPersister Object ( [class:protected] => Doctrine\ORM\Mapping\ClassMetadata Object ( [name] => TDS\Entity\Courses [namespace] => TDS\Entity [rootEntityName] => TDS\Entity\Courses [customGeneratorDefinition] => [customRepositoryClassName] => [isMappedSuperclass] => [isEmbeddedClass] => [parentClasses] => Array ( ) [subClasses] => Array ( ) [embeddedClasses] => Array ( ) [namedQueries] => Array ( ) [namedNativeQueries] => Array ( ) [sqlResultSetMappings] => Array ( ) [identifier] => Array ( [0] => id ) [inheritanceType] => 1 [generatorType] => 4 [fieldMappings] => Array ( [id] => Array ( [fieldName] => id [type] => integer [scale] => 0 [length] => [unique] => [nullable] => [precision] => 0 [columnName] => id [id] => 1 ) [name] => Array ( [fieldName] => name [type] => string [scale] => 0 [length] => 64 [unique] => [nullable] => [precision] => 0 [columnName] => name ) ) [fieldNames] => Array ( [id] => id [name] => name ) [columnNames] => Array ( [id] => id [name] => name ) [discriminatorValue] => [discriminatorMap] => Array ( ) [discriminatorColumn] => [table] => Array ( [name] => courses ) [lifecycleCallbacks] => Array ( ) [entityListeners] => Array ( ) [associationMappings] => Array ( ) [isIdentifierComposite] => [containsForeignIdentifier] => [idGenerator] => Doctrine\ORM\Id\IdentityGenerator Object ( [sequenceName:Doctrine\ORM\Id\IdentityGenerator:private] => ) [sequenceGeneratorDefinition] => [tableGeneratorDefinition] => [changeTrackingPolicy] => 1 [isVersioned] => [versionField] => [cache] => [reflClass] => ReflectionClass Object ( [name] => TDS\Entity\Courses ) [isReadOnly] => [namingStrategy:protected] => Doctrine\ORM\Mapping\DefaultNamingStrategy Object ( ) [reflFields] => Array ( [id] => ReflectionProperty Object ( [name] => id [class] => TDS\Entity\Courses ) [name] => ReflectionProperty Object ( [name] => name [class] => TDS\Entity\Courses ) ) [instantiator:Doctrine\ORM\Mapping\ClassMetadataInfo:private] => Doctrine\Instantiator\Instantiator Object ( ) ) [conn:protected] => Doctrine\DBAL\Connection Object ( [_conn:protected] => Doctrine\DBAL\Driver\PDOConnection Object ( ) [_config:protected] => Doctrine\ORM\Configuration Object ( [_attributes:protected] => Array ( [autoGenerateProxyClasses] => 1 [proxyDir] => data/DoctrineORMModule/Proxy [proxyNamespace] => DoctrineORMModule\Proxy [entityNamespaces] => Array ( ) [customStringFunctions] => Array ( [unix_timestamp] => Swing\Utils\UnixTimestamp ) [classMetadataFactoryName] => Doctrine\ORM\Mapping\ClassMetadataFactory [metadataCacheImpl] => Doctrine\Common\Cache\ArrayCache Object ( [data:Doctrine\Common\Cache\ArrayCache:private] => Array ( [DoctrineNamespaceCacheKey[DoctrineModule]] => 1 [DoctrineModule[TDS\Entity\Courses@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Table] => Doctrine\ORM\Mapping\Table Object ( [name] => courses [schema] => [indexes] => [uniqueConstraints] => [options] => Array ( ) ) [Doctrine\ORM\Mapping\Entity] => Doctrine\ORM\Mapping\Entity Object ( [repositoryClass] => [readOnly] => ) ) [DoctrineModule[TDS\Entity\Courses$id@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Column] => Doctrine\ORM\Mapping\Column Object ( [name] => id [type] => integer [length] => [precision] => 0 [scale] => 0 [unique] => [nullable] => [options] => Array ( ) [columnDefinition] => ) [Doctrine\ORM\Mapping\Id] => Doctrine\ORM\Mapping\Id Object ( ) [Doctrine\ORM\Mapping\GeneratedValue] => Doctrine\ORM\Mapping\GeneratedValue Object ( [strategy] => IDENTITY ) ) [DoctrineModule[TDS\Entity\Courses$name@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Column] => Doctrine\ORM\Mapping\Column Object ( [name] => name [type] => string [length] => 64 [precision] => 0 [scale] => 0 [unique] => [nullable] => [options] => Array ( ) [columnDefinition] => ) ) [DoctrineModule[TDS\Entity\Courses$CLASSMETADATA][1]] => Doctrine\ORM\Mapping\ClassMetadata Object ( [name] => TDS\Entity\Courses [namespace] => TDS\Entity [rootEntityName] => TDS\Entity\Courses [customGeneratorDefinition] => [customRepositoryClassName] => [isMappedSuperclass] => [isEmbeddedClass] => [parentClasses] => Array ( ) [subClasses] => Array ( ) [embeddedClasses] => Array ( ) [namedQueries] => Array ( ) [namedNativeQueries] => Array ( ) [sqlResultSetMappings] => Array ( ) [identifier] => Array ( [0] => id ) [inheritanceType] => 1 [generatorType] => 4 [fieldMappings] => Array ( [id] => Array ( [fieldName] => id [type] => integer [scale] => 0 [length] => [unique] => [nullable] => [precision] => 0 [columnName] => id [id] => 1 ) [name] => Array ( [fieldName] => name [type] => string [scale] => 0 [length] => 64 [unique] => [nullable] => [precision] => 0 [columnName] => name ) ) [fieldNames] => Array ( [id] => id [name] => name ) [columnNames] => Array ( [id] => id [name] => name ) [discriminatorValue] => [discriminatorMap] => Array ( ) [discriminatorColumn] => [table] => Array ( [name] => courses ) [lifecycleCallbacks] => Array ( ) [entityListeners] => Array ( ) [associationMappings] => Array ( ) [isIdentifierComposite] => [containsForeignIdentifier] => [idGenerator] => Doctrine\ORM\Id\IdentityGenerator Object ( [sequenceName:Doctrine\ORM\Id\IdentityGenerator:private] => ) [sequenceGeneratorDefinition] => [tableGeneratorDefinition] => [changeTrackingPolicy] => 1 [isVersioned] => [versionField] => [cache] => [reflClass] => ReflectionClass Object ( [name] => TDS\Entity\Courses ) [isReadOnly] => [namingStrategy:protected] => Doctrine\ORM\Mapping\DefaultNamingStrategy Object ( ) [reflFields] => Array ( [id] => ReflectionProperty Object ( [name] => id [class] => TDS\Entity\Courses ) [name] => ReflectionProperty Object ( [name] => name [class] => TDS\Entity\Courses ) ) [instantiator:Doctrine\ORM\Mapping\ClassMetadataInfo:private] => Doctrine\Instantiator\Instantiator Object ( ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Table] => Doctrine\ORM\Mapping\Table Object ( [name] => courses_levels_places [schema] => [indexes] => Array ( [0] => Doctrine\ORM\Mapping\Index Object ( [name] => courses [columns] => Array ( [0] => id_course ) [flags] => [options] => ) [1] => Doctrine\ORM\Mapping\Index Object ( [name] => levels [columns] => Array ( [0] => id_level ) [flags] => [options] => ) [2] => Doctrine\ORM\Mapping\Index Object ( [name] => places [columns] => Array ( [0] => id_place ) [flags] => [options] => ) [3] => Doctrine\ORM\Mapping\Index Object ( [name] => time_slot [columns] => Array ( [0] => id_time_slot ) [flags] => [options] => ) ) [uniqueConstraints] => [options] => Array ( ) ) [Doctrine\ORM\Mapping\Entity] => Doctrine\ORM\Mapping\Entity Object ( [repositoryClass] => [readOnly] => ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$id@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Column] => Doctrine\ORM\Mapping\Column Object ( [name] => id [type] => integer [length] => [precision] => 0 [scale] => 0 [unique] => [nullable] => [options] => Array ( ) [columnDefinition] => ) [Doctrine\ORM\Mapping\Id] => Doctrine\ORM\Mapping\Id Object ( ) [Doctrine\ORM\Mapping\GeneratedValue] => Doctrine\ORM\Mapping\GeneratedValue Object ( [strategy] => IDENTITY ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$idCourse@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\ManyToOne] => Doctrine\ORM\Mapping\ManyToOne Object ( [targetEntity] => TDS\Entity\Courses [cascade] => [fetch] => LAZY [inversedBy] => ) [Doctrine\ORM\Mapping\JoinColumns] => Doctrine\ORM\Mapping\JoinColumns Object ( [value] => Array ( [0] => Doctrine\ORM\Mapping\JoinColumn Object ( [name] => id_course [referencedColumnName] => id [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [fieldName] => ) ) ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$idLevel@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\ManyToOne] => Doctrine\ORM\Mapping\ManyToOne Object ( [targetEntity] => TDS\Entity\Levels [cascade] => [fetch] => LAZY [inversedBy] => ) [Doctrine\ORM\Mapping\JoinColumns] => Doctrine\ORM\Mapping\JoinColumns Object ( [value] => Array ( [0] => Doctrine\ORM\Mapping\JoinColumn Object ( [name] => id_level [referencedColumnName] => id [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [fieldName] => ) ) ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$idPlace@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\ManyToOne] => Doctrine\ORM\Mapping\ManyToOne Object ( [targetEntity] => TDS\Entity\Places [cascade] => [fetch] => LAZY [inversedBy] => ) [Doctrine\ORM\Mapping\JoinColumns] => Doctrine\ORM\Mapping\JoinColumns Object ( [value] => Array ( [0] => Doctrine\ORM\Mapping\JoinColumn Object ( [name] => id_place [referencedColumnName] => id [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [fieldName] => ) ) ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$idTimeSlot@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\ManyToOne] => Doctrine\ORM\Mapping\ManyToOne Object ( [targetEntity] => TDS\Entity\TimeSlot [cascade] => [fetch] => LAZY [inversedBy] => ) [Doctrine\ORM\Mapping\JoinColumns] => Doctrine\ORM\Mapping\JoinColumns Object ( [value] => Array ( [0] => Doctrine\ORM\Mapping\JoinColumn Object ( [name] => id_time_slot [referencedColumnName] => id [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [fieldName] => ) ) ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$CLASSMETADATA][1]] => Doctrine\ORM\Mapping\ClassMetadata Object ( [name] => TDS\Entity\CoursesLevelsPlaces [namespace] => TDS\Entity [rootEntityName] => TDS\Entity\CoursesLevelsPlaces [customGeneratorDefinition] => [customRepositoryClassName] => [isMappedSuperclass] => [isEmbeddedClass] => [parentClasses] => Array ( ) [subClasses] => Array ( ) [embeddedClasses] => Array ( ) [namedQueries] => Array ( ) [namedNativeQueries] => Array ( ) [sqlResultSetMappings] => Array ( ) [identifier] => Array ( [0] => id ) [inheritanceType] => 1 [generatorType] => 4 [fieldMappings] => Array ( [id] => Array ( [fieldName] => id [type] => integer [scale] => 0 [length] => [unique] => [nullable] => [precision] => 0 [columnName] => id [id] => 1 ) ) [fieldNames] => Array ( [id] => id ) [columnNames] => Array ( [id] => id ) [discriminatorValue] => [discriminatorMap] => Array ( ) [discriminatorColumn] => [table] => Array ( [name] => courses_levels_places [indexes] => Array ( [courses] => Array ( [columns] => Array ( [0] => id_course ) ) [levels] => Array ( [columns] => Array ( [0] => id_level ) ) [places] => Array ( [columns] => Array ( [0] => id_place ) ) [time_slot] => Array ( [columns] => Array ( [0] => id_time_slot ) ) ) ) [lifecycleCallbacks] => Array ( ) [entityListeners] => Array ( ) [associationMappings] => Array ( [idCourse] => Array ( [fieldName] => idCourse [joinColumns] => Array ( [0] => Array ( [name] => id_course [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [referencedColumnName] => id ) ) [cascade] => Array ( ) [inversedBy] => [targetEntity] => TDS\Entity\Courses [fetch] => 2 [type] => 2 [mappedBy] => [isOwningSide] => 1 [sourceEntity] => TDS\Entity\CoursesLevelsPlaces [isCascadeRemove] => [isCascadePersist] => [isCascadeRefresh] => [isCascadeMerge] => [isCascadeDetach] => [sourceToTargetKeyColumns] => Array ( [id_course] => id ) [joinColumnFieldNames] => Array ( [id_course] => id_course ) [targetToSourceKeyColumns] => Array ( [id] => id_course ) [orphanRemoval] => ) [idLevel] => Array ( [fieldName] => idLevel [joinColumns] => Array ( [0] => Array ( [name] => id_level [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [referencedColumnName] => id ) ) [cascade] => Array ( ) [inversedBy] => [targetEntity] => TDS\Entity\Levels [fetch] => 2 [type] => 2 [mappedBy] => [isOwningSide] => 1 [sourceEntity] => TDS\Entity\CoursesLevelsPlaces [isCascadeRemove] => [isCascadePersist] => [isCascadeRefresh] => [isCascadeMerge] => [isCascadeDetach] => [sourceToTargetKeyColumns] => Array ( [id_level] => id ) [joinColumnFieldNames] => Array ( [id_level] => id_level ) [targetToSourceKeyColumns] => Array ( [id] => id_level ) [orphanRemoval] => ) [idPlace] => Array ( [fieldName] => idPlace [joinColumns] => Array ( [0] => Array ( [name] => id_place [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [referencedColumnName] => id ) ) [cascade] => Array ( ) [inversedBy] => [targetEntity] => TDS\Entity\Places [fetch] => 2 [type] => 2 [mappedBy] => [isOwningSide] => 1 [sourceEntity] => TDS\Entity\CoursesLevelsPlaces [isCascadeRemove] => [isCascadePersist] => [isCascadeRefresh] => [isCascadeMerge] => [isCascadeDetach] => [sourceToTargetKeyColumns] => Array ( [id_place] => id ) [joinColumnFieldNames] => Array ( [id_place] => id_place ) 

这是我提出请求的方式:

$qb = $this->getEm()->createQueryBuilder();
$qb->select('clp')->from('TDS\Entity\CoursesLevelsPlaces', 'clp');
$list = $qb->getQuery()->getResult();

问题是我无法检索我的实体。例如,如果我在 Courses 上发出请求,结果会正确显示。 每个 CoursesLevelsPlaces 行都是唯一的,并且与其他实体具有一对一的关系。

作为参考,我从我的数据库模式中生成了这些实体(反向原则)

你知道我为什么会得到这个结果吗? 谢谢

你不应该 print_rvar_dump 完整的学说 2 实体,因为所有的元数据等也将被打印出来。这将导致内存问题,并且输出对于您的浏览器来说太多了。

你有几个选择

  • 只需遍历您的结果并使用 getter 检索数据。

    foreach ($list as $entity) {
        echo $entity->getId() . PHP_EOL;
    }
    
  • 使用 doctrine 中的调试工具。

    foreach ($list as $entity) {
        Doctrine\Common\Util\Debug::dump($entity);
    }
    
  • 使用调试器 (xdebug) 并在您的 IDE 中放置一个断点并观察实体内容