[英]Simple DQL request using Doctrine2 & Postgresql
I want to use the query_builder in a Symfony2 FormType, I tried to make a simple request in my Postgresql shema using Doctrine DQL. 我想在Symfony2 FormType中使用query_builder,我尝试使用Doctrine DQL在我的Postgresql shema中提出一个简单的请求。 It return me an error and i don't really understand how fix it : 它给我返回一个错误,我不太了解如何解决:
PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "" AS id0 FROM ""
LINE 1: SELECT "0_."id" AS id0 FROM "DATA_WAREHOUSE"."WindFarm" "0_
This is the Windfarm class : 这是风电场类:
<?php
namespace Base\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* WindFarm
*
* @ORM\Table(name="""DATA_WAREHOUSE"".""WindFarm""")
* @ORM\Entity(repositoryClass="Base\CoreBundle\Repository\WindFarmRepository")
*/
class WindFarm
{
/**
* @ORM\OneToMany(targetEntity="Base\CoreBundle\Entity\Turbine", mappedBy="windFarm")
*/
private $turbines;
/**
* @var string $id
*
* @ORM\Column(name="""id""", type="string", length=32)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\SequenceGenerator(sequenceName="""DATA_WAREHOUSE"".""WindFarm_id_seq""", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var string $name
*
* @ORM\Column(name="""name""", type="text", nullable=true)
*/
private $name;
/**
* @var string $alias
*
* @ORM\Column(name="""alias""", type="string", length=32, nullable=true)
*/
private $alias;
/**
* @var string $location
*
* @ORM\Column(name="""location""", type="text", nullable=true)
*/
private $location;
/**
* @var string $sncNbr
*
* @ORM\Column(name="""sncNbr""", type="string", length=8, nullable=true)
*/
private $sncNbr;
}
The DQL request in the WindFarmRepository: WindFarmRepository中的DQL请求:
public function getWindFarmsAndTurbines(){
$qb = $this->createQueryBuilder()
->select('wft')
->from('BaseCoreBundle:WindFarm', 'wft')
->leftJoin('wft.turbines', 't')
->addSelect('t')
->orderBy('t.alias');
return $qb;
}
The FormType : FormType:
<?php
namespace Base\CoreBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Base\CoreBundle\Repository\WindFarmRepository;
class TurbineStatusCodeType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('exportBegin', 'date', array('input' => 'datetime',
'widget' => 'single_text',
'format' => 'yyyy-MM-dd',))
->add('exportEnd', 'date', array('input' => 'datetime',
'widget' => 'single_text',
'format' => 'yyyy-MM-dd',))
->add('arrayId', 'textarea')
->add('turbines', 'entity', array('class' => 'BaseCoreBundle:WindFarm',
'property' => 'name',
'multiple' => true,
'expanded' => true,
'query_builder' => function(WindFarmRepository $repo){
return $repo->getWindFarmsAndTurbines();
}))
->add('save', 'submit');
}
/**
* @return string
*/
public function getName()
{
return 'base_corebundle_turbineStatusCodeType';
}
}
apparently, the problem is situated in the quote, I tried many solutions, but nothing work. 显然,问题出在报价单上,我尝试了许多解决方案,但没有任何效果。
All of your Doctrine annotations are incorrect and have extra double-quotes. 您的所有教义注释均不正确,并带有多余的双引号。
@ORM\Column(name="""id""", type="string", length=32)
should be 应该
@ORM\Column(name="id", type="string", length=32)
and so on 等等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.