我正在尝试从symfony中的嵌套树结构生成JSON文件。 它用于jquery-fancytree。因此,我正在研究sql查询。
但是我的RolesRepository给出了
错误:预期的学说\ ORM \ Query \ Lexer :: T_IDENTIFIER,得到了“ *”
SQL查询手动工作
class RolesRepository extends \Doctrine\ORM\EntityRepository
{
public function getNestedToJSON()
{
$em = $this->getEntityManager();
$query = $em->createQuery(
'SELECT n.* , round((n.Rght-n.Lft-1)/2,0) AS offspring,
count(*)-1 + (n.Lft>1) AS level,
((min(p.Rght)-n.Rght-( n.Lft >1 ))/2) > 0 AS lower,
(((n.Lft-max(p.Lft)>1))) AS upper
FROM md_roles n, md_roles p
WHERE n.Lft BETWEEN p.Lft AND p.Rght
AND (p.id != n.id OR n.Lft = 1)
GROUP BY n.id
ORDER BY n.Lft')
->getResult();
return $query;
}
}
实体:
/**
* UserRoles
*
* @ORM\Table(name="md_roles",
* options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"InnoDB"})
* @ORM\Entity(repositoryClass="AppBundle\Repository\RolesRepository")
*/
class Roles
{
/**
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Id
*/
protected $ID;
/**
* @ORM\Column(name="Lft", columnDefinition="INT(11) NOT NULL")
*/
protected $Lft;
/**
* @ORM\Column(name="Rght", columnDefinition="INT(11) NOT NULL")
*/
protected $Rght;
/**
* @ORM\Column(name="Title", columnDefinition="char(128) NOT NULL")
*/
protected $Title;
/**
* @ORM\Column(name="Description", columnDefinition="text NOT NULL")
*/
protected $Description;
/**
* @return integer
*/
public function getID()
{
return $this->ID;
}
/**
* @return Roles
*/
public function setID($ID)
{
$this->ID = $ID;
return $this;
}
/**
* @return mixed
*/
public function getLft()
{
return $this->Lft;
}
/**
* @param mixed $Lft
* @return Roles
*/
public function setLft($Lft)
{
$this->Lft = $Lft;
return $this;
}
/**
* @return mixed
*/
public function getRght()
{
return $this->Rght;
}
/**
* @param mixed $Rght
* @return Roles
*/
public function setRght($Rght)
{
$this->Rght = $Rght;
return $this;
}
/**
* @return mixed
*/
public function getTitle()
{
return $this->Title;
}
/**
* @param mixed $Title
* @return Roles
*/
public function setTitle($Title)
{
$this->Title = $Title;
return $this;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->Description;
}
/**
* @param mixed $Description
* @return Roles
*/
public function setDescription($Description)
{
$this->Description = $Description;
return $this;
}
}
有人知道为什么吗?
答案 0 :(得分:4)
您尝试执行SQL
,但是此函数需要一个DQL
字符串。而是将$em->createNativeQuery()
用于纯SQL语句,或将SQL转换为等效的DQL表达式。