Search code examples
symfonydoctrine-ormdql

DQL Symfony 2, Set boolean value


i have a problem about DQL Symfony 2, i want to set the first value in my select. The value is boolean, but i can't do this. this is my code :

    public function findAllMenuListForMenuGroup(){
    $query = $this->getEntityManager()
        ->createQueryBuilder()
        ->select('a.id, a.lft, a.lvl, a.rgt, a.name, a.title, true as value, a.description')
        ->from(Menu::class,'a')
        ->orderBy('a.root, a.lft','ASC')
        ->getQuery();
    return $query->getArrayResult();
}

this code is error but i don't know the problems, look the code "true as value", i feel there is the problem, anyone can help me ?

the error is :

[Syntax Error] line 0, col 51: Error: Expected IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression, got 'true'

    /**
 * @ORM\Id()
 * @ORM\Column(name="id", type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @ORM\ManyToMany(targetEntity="Menu", inversedBy="menuGroup")
 * @ORM\JoinTable(name="administration_menu_group_details")
 */
private $menu;

/**
 * @ORM\OneToMany(targetEntity="User", mappedBy="menuGroup")
 */
private $user;

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

/**
 * @var string
 *
 * @ORM\Column(name="description", type="string", length=1000)
 */
private $description;

Solution

  • try with

    1 as value 
    

    instead of

    true as value
    

    Probably you must enclose in " character.

    Also, You need to use addOrderBy instead of orderBy as follow:

        ->addOrderBy('a.root','ASC')
        ->addOrderBy('a.lft','ASC')
    

    Instead of:

        ->orderBy('a.root, a.lft','ASC')
    

    Hope this help