Я пытаюсь создать файл JSON из вложенной древовидной структуры в symfony. Он используется для jquery-fancytree. Поэтому я работаю над sql-запросом.
Но мой RolesRepository выдает
Ошибка: ожидаемая Doctrine \ 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;
}
}
Кто-нибудь знает почему?




Вы пытаетесь выполнить SQL, но эта функция ожидает строку DQL. Вместо этого используйте $em->createNativeQuery() для простых операторов SQL или преобразуйте свой SQL в эквивалентное выражение DQL.
Спасибо за вашу помощь