在查询生成器中创建JOIN查询以形成doctrine symfony2

时间:2016-05-31 10:27:06

标签: forms symfony join doctrine-orm query-builder

我试图创建一个与SQL句子类似的连接句子:

window.btoa(svg)

我正在使用symfony中的学说形式,我目前的形式是下一个:

SELECT p.* FROM personal p INNER JOIN tematica_soporte ts ON ts.personalEmail = p.email ORDER BY ts.orden

问题在于我需要命令对象' p'通过tematica_soporte.order。我在学说上开始,我很高兴能帮到你。

我相信它应该是这样的:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('consultanteemail', new ConsultanteType(), array ('label' => false))
        ->add('personalemail', 'entity', array(
            'label' => 'Personal de Soporte',
            'class' => 'GuiasDocentes\AppBundle\Entity\Personal',
            'property' => 'Enunciado',
            'by_reference' => 'false',
            'query_builder' => function(PersonalRepository $pr) {
                $query= $pr->createQueryBuilder('p')
                ;
                return $query;
            },
            'empty_value' => 'Elija una temática para su consulta:',
            ))
    ;
}

PersonalRepository.php

    public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('consultanteemail', new ConsultanteType(), array ('label' => false))
        ->add('personalemail', 'entity', array(
            'label' => 'Personal de Soporte',
            'class' => 'GuiasDocentes\AppBundle\Entity\Personal',
            'property' => 'Enunciado',
            'by_reference' => 'false',
            'query_builder' => function(PersonalRepository $pr) {
                return $pr->getPersonalOrdered();
            },
            'empty_value' => 'Elija una temática para su consulta:',
            ))
    ;
}

然而,它引发了一个奇怪的错误:

    public function getPersonalOrdered(){
    $query = $this->createQueryBuilder('p')
        ->from('GuiasDocentesAppBundle:Personal', 'p')
        ->innerJoin('GuiasDocentesAppBundle:TematicaSoporte', 'ts')
        ->where('ts.personalemail = p.email')                
        ->orderBy("ts.order");
    return $query;
}

这些是牵连的实体:

Personal.php

[Syntax Error] line 0, col 108: Error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got ','

TematicaSoporte.php

class Personal{
/**
 * @var string
 *
 * @ORM\Column(name="email", type="string", length=50, nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $email;

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

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

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

/* Customized code */
/**
 * @ORM\OneToMany(targetEntity="GuiasDocentes\AppBundle\Entity\TematicaSoporte", mappedBy="personalEmail")
 * @Assert\Valid()
 */    
private $tematicasSoporte;

public function __constructor(){
    $this->tematicasSoporte = new ArrayCollection();
    $this->hilos = new ArrayCollection();
}

public function addTematicasSoporte(\GuiasDocentes\AppBundle\Entity\TematicaSoporte $tematicaSoporte){
    $this->tematicasSoporte[] = $tematicaSoporte;
    return $this;
}    

public function setTematicasSoporte(\GuiasDocentes\AppBundle\Entity\TematicaSoporte $tematicaSoporte){
    $this->tematicasSoporte[] = $tematicaSoporte;
    return $this;
}

public function getTematicasSoporte(){
    return $this->tematicasSoporte;
}
....

...

0 个答案:

没有答案
相关问题