drpogkqqi536984960 2016-08-08 14:46
浏览 84

使用Symfony在PHP中查询MySql

What is difference between

In application 1 / 2:

$qb = $this->createQueryBuilder('tu');

                $transUnits = $qb->select('tu, te')
                    ->leftJoin('tu.translations', 'te')
                    ->andWhere($qb->expr()->in('tu.id', $ids))
                    ->andWhere($qb->expr()->in('te.locale', $locales))
                    ->orderBy(sprintf('tu.%s', $sortColumn), $order)
                    ->getQuery()
                    ->getArrayResult();

and

$qb = $this->createQueryBuilder('tu');

                $transUnits = $qb->select('tu, te')
                    ->leftJoin('AppBundle:Translation', 'te')
                    ->andWhere($qb->expr()->in('tu.id', $ids))
                    ->andWhere($qb->expr()->in('te.locale', $locales))
                    ->orderBy(sprintf('tu.%s', $sortColumn), $order)
                    ->getQuery()
                    ->getArrayResult();

The functions are called with the exact same parameters.

In the second case I replace 'tu.translations' with 'AppBundle:Translation' because do not recognize 'translations' where translations is define:

<one-to-many field="translations" target-entity="TranslationBundle\Entity\Translation" mapped-by="transUnit">
            <cascade>
                <cascade-all/>
            </cascade>
</one-to-many>

In the first case result is: array(13) { ... } and this is the correct format result; in the second case wrong format result is: array(70) { ... }

  • 写回答

1条回答 默认 最新

  • dongpan8439 2016-08-09 06:14
    关注

    I add in entity class:

    /**
         * @var \Translation
         * @ORM\OneToMany(targetEntity="Translation", mappedBy="transUnit")
         * @ORM\JoinColumns({
         *   @ORM\JoinColumn(name="id", referencedColumnName="trans_unit_id")
         * })
         */
        protected $translations;
    

    and

    /**
         * @var \TransUnit
         *
         * @ORM\ManyToOne(targetEntity="TransUnit", inversedBy="translations")
         * @ORM\JoinColumns({
         *   @ORM\JoinColumn(name="trans_unit_id", referencedColumnName="id")
         * })
         */
        protected $transUnit;
    

    And work. :)

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)