我对简单的树结构有奇怪的问题..
class CourseCategory {
/** @Id @Column(name="Id", type="integer", unique=true)
* @GeneratedValue
*/
private $id = null;
/** @Column(name="Name", length=2000) */
private $name;
/**
* @OneToOne(targetEntity="CourseCategory")
* @JoinColumn(name="ParentId", referencedColumnName="Id", nullable=true)
**/
private $parent;
/** @Column(name="Slug", length=255) */
private $slug;
/** @Column(name="PageTitle", length=2000) */
private $pageTitle;
/** @Column(name="Order", type="integer") */
private $order;
public function __construct($name, $parent, $slug, $pageTitle, $order) {
$this->name = $name;
$this->parent = $parent;
$this->slug = $slug;
$this->pageTitle = $pageTitle;
$this->order = $order;
}
}
添加新类别:
$category = new CourseCategory($name, $parentCategory, $slug, $pageTitle,
$em->createQuery('SELECT COUNT(c.id) FROM Entity\CourseCategory c')->getSingleScalarResult() + 1);
$em->persist($category);
$em->flush();
此代码因Syntax error or access violation: 1064
异常而失败。它以某种方式尝试将字符串添加到 ParentId 字段中:
check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order, ParentId) VALUES ('123', '123', '123', 47, '1')
有人知道为什么会这样吗?谢谢