Php 具有实体存储库和查询生成器的实体字段类型
我使用实体字段类型query\u builder在下拉列表中仅显示这些不是父类的类型(父类\u id==null)。我的ProductionType实体:Php 具有实体存储库和查询生成器的实体字段类型,php,doctrine-orm,symfony-2.5,Php,Doctrine Orm,Symfony 2.5,我使用实体字段类型query\u builder在下拉列表中仅显示这些不是父类的类型(父类\u id==null)。我的ProductionType实体: <?php namespace RFQ\IronilBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * ProductionType * * @ORM\Table(name="production_type") * @ORM\Entity(repositoryClas
<?php
namespace RFQ\IronilBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ProductionType
*
* @ORM\Table(name="production_type")
* @ORM\Entity(repositoryClass="RFQ\IronilBundle\Entity\ProductionTypeRepository")
*/
class ProductionType
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string")
*/
protected $name;
/**
* @ORM\OneToMany(targetEntity="ProductionType", mappedBy="parent")
**/
protected $children;
/**
* @ORM\ManyToOne(targetEntity="ProductionType", inversedBy="children")
**/
protected $parent;
// setters, getters and constructors...
因此,我有以下错误:
Class "RFQ\IronilBundle\Entity\ProductionTypeRepository" seems not to be a managed Doctrine entity. Did you forget to map it?
我为此花了很多时间,但我不明白为什么我失败了
多谢各位
更新
我刚刚将表单生成器下拉字段代码更改为:
->add('parent', 'entity', array('label' => 'Parent',
'class' => 'RFQ\IronilBundle\Entity\ProductionType',
'query_builder' => function(ProductionTypeRepository $repository) {
return $repository->createQueryBuilder('s')->orderBy('s.id', 'ASC');},
'attr' => array('class'=>'form-control login-input')))
和存储库方法,以:
public function findAllParents()
{
return $this->_em->createQuery('SELECT * FROM RFQIronilBundle:ProductionType WHERE parent_id = null')
->getResult();
}
在结果中,我并没有错误,但我的查询返回所有结果,但我如何说我需要在parent_id==null的位置获得结果。什么是正确的查询?获取实体的存储库
$results=$this->getDoctrine()
->getRepository('RFQ\IronilBundle\Entity\ProductionType')
->findAllParents()代码>
为空
从
SELECT*FROM RFQIronilBundle:ProductionType,其中parent\u id=null
到
SELECT*FROM RFQIronilBundle:ProductionType,其中父项id为NULL
在findAllParents()
:->中相同,其中('a.parent\u id为NULL')代码>你是对的!非常感谢你!你救了我的时间!
->add('parent', 'entity', array('label' => 'Parent',
'class' => 'RFQ\IronilBundle\Entity\ProductionType',
'query_builder' => function(ProductionTypeRepository $repository) {
return $repository->createQueryBuilder('s')->orderBy('s.id', 'ASC');},
'attr' => array('class'=>'form-control login-input')))
public function findAllParents()
{
return $this->_em->createQuery('SELECT * FROM RFQIronilBundle:ProductionType WHERE parent_id = null')
->getResult();
}