Symfony 3,不能在查询前键中获取原则

时间:2018-07-12 08:51:09

标签: symfony doctrine symfony-3.3 symfony-3.4

嘿,我有下一张桌子:

Urls, CREATE TABLE `Urls` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `root` int(11) DEFAULT NULL,
  `url` varchar(2000) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  KEY `fk_Url_1_idx` (`root`),
  CONSTRAINT `fk_Url_1` FOREIGN KEY (`root`) REFERENCES `Enlaces` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

当我执行查询以获取数据时

$urls = $this->getDoctrine()->getManager()->getRepository('UserBundle:Urls')
            ->createQueryBuilder('e')
            ->select("e")
            ->getQuery()->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);

查询获取除根以外的所有字段。

但是,当执行php bin / console指令时:获取查询:sql根目录

实体文件Urls.php:

    <?php

namespace UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Urls
 *
 * @ORM\Table(name="Urls", uniqueConstraints={@ORM\UniqueConstraint(name="id_UNIQUE", columns={"id"})}, indexes={@ORM\Index(name="fk_Url_1_idx"})
 * @ORM\Entity
 */
class Urls
{
    /**
     * @var string|null
     *
     * @ORM\Column(name="url", type="string", length=2000, nullable=true)
     */
    private $url;

    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \UserBundle\Entity\Urls
     *
     * @ORM\ManyToOne(targetEntity="UserBundle\Entity\Urls")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="root", referencedColumnName="id")
     * })
     */
    private $root;
}

有什么主意吗?

1 个答案:

答案 0 :(得分:0)

我解决了添加-> setHint(\ Doctrine \ ORM \ Query :: HINT_INCLUDE_META_COLUMNS,true)进行查询的问题。

$urls = $this->getDoctrine()->getManager()->getRepository('UserBundle:Urls')
            ->createQueryBuilder('e')
            ->select("e")
            ->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, true)
            ->getQuery()->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);