Rachmat Chang
Rachmat Chang

Reputation: 197

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;

Upvotes: 1

Views: 1624

Answers (3)

Massimiliano Arione
Massimiliano Arione

Reputation: 2466

Don't do it in DQL. Add a method to your object that is returning always true. Then remove select from your DQL.

Upvotes: 0

Matteo
Matteo

Reputation: 39380

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

Upvotes: 0

eeXBee
eeXBee

Reputation: 133

Doctrine Uses it's own aliases. You can't use "as" here.

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

Upvotes: 1

Related Questions