dougu8742
2016-12-16 05:31
浏览 75
已采纳

Doctrine join语法错误

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.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duandaoji3992 2016-12-16 06:24
    已采纳

    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'); 
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题