I have strange issue with simple tree structure..
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;
}
}
Adding new category:
$category = new CourseCategory($name, $parentCategory, $slug, $pageTitle,
$em->createQuery('SELECT COUNT(c.id) FROM Entity\CourseCategory c')->getSingleScalarResult() + 1);
$em->persist($category);
$em->flush();
This code fails with Syntax error or access violation: 1064
exception. Somehow it tries to add string into ParentId field:
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')
Do somebody know why it happens? Thank you