Haruji Burke
Haruji Burke

Reputation: 459

Doctrine join syntax is wrong

I'm writing my CMS with my own frame, using doctrince 2.5+.

My database table like this:

Item table:

+---------------------+-------------+------+-----+---------+-------+
| Field               | Type        | Null | Key | Default | Extra |
+---------------------+-------------+------+-----+---------+-------+
| id                  | int(11)     | NO   | PRI | NULL    |       |
| owner_id            | int(11)     | NO   | MUL | NULL    |       |
| item_id             | int(7)      | NO   | MUL | NULL    |       |
| count               | bigint(20)  | NO   |     | NULL    |       |
| money               | varchar(32) | NO   |     | NULL    |       |
| name                | varchar(32) | NO   |     | NULL    |       |
+---------------------+-------------+------+-----+---------+-------+

Person table:

+------------------------+----------------------+------+-----+---------+-------+
| Field                  | Type                 | Null | Key | Default | Extra |
+------------------------+----------------------+------+-----+---------+-------+
| Id                     | int(11)              | NO   | PRI | 0       |       |
| name                   | varchar(35)          | NO   | UNI |         |       |
| age                    | int                  | NO   |     |         |       |
+------------------------+----------------------+------+-----+---------+-------+

I declared models like these: Item.php

class Item{
    /** @id @Column(type="integer", name="id")**/
    public $id;
    /** @Column(type="integer", name="owner_id")**/
    public $owner_id;
    /** @Column(type="integer", name = "item_id")**/
    public $item_id;
    /** @Column(type="bigint", name = "count")**/
    public $count;
    /** @Column(type="string", name = "money")**/
    public $money;
    /** @Column(type="string", name = "name")**/
    public $name;
}

Pesron.php

 class Person{
        /** @id @Column(type="integer", name="Id")**/
        public $id;
        /** @Column(type="string", name="name", unique=true)**/
        public $name;
        /** @Column(type="integer", name="age")**/
        public $age;
 }

As above, i have no associations here. My DQl is:

    $qb = $this->em->createQueryBuilder();  
    $qb->select('i.id,i.item_id,i.enchant_level, i.owner_id,p.char_name,p.id')
        ->from('Item','i');
        $qb->join('Person','p','WITH','i.owner_id == p.id');    

Doctrine can't parse the DQL. Why??? I take a look into document's document but dunno why. Without with the result is wrong. Thanks in advance.

Upvotes: 1

Views: 56

Answers (1)

sg-
sg-

Reputation: 2176

Doctrine is right - that's not valid DQL because you are using double equals (==). You probably want this:

$qb->join('Person','p','WITH','i.owner_id = p.id'); 

Upvotes: 3

Related Questions