我有这样的实体:
/** * * @Table(name="table") * @Entity */ class Table { /** * @Column(type="integer") * @Id * @GeneratedValue(strategy="IDENTITY") */ private $id; /** * @ManyToOne(targetEntity="Entities\Users") * @joinColumn(name="userId",referencedColumnName="id") */ private $User; /** * @Column(type="string") */ private $text; }
如果我做
$Q-> getQuery() – > getSingleResult() – >的getUser() – > getUserId()
SELECT * FROM table t INNER JOIN users u ON u.id = t.userId WHERE id = 100
在纯sql中,我可以只是
SELECT * FROM table WHERE id = 100
您可能还需要查看IDENTITY()函数(Doctrine版本> 2.2).
原文链接:https://www.f2er.com/php/131492.html例:
SELECT IDENTITY(t.User) AS user_id from Table
应该返回:
[ ['user_id' => 1],['user_id' => 2],... ]