Details
Description
namespace Entities; //use Doctrine\Common\Collections\ArrayCollection; /** *@Entity *@Table(name="user") */ class User { /** *@Id *@Column(type="integer", name="user_id") *@GeneratedValue * */ private $userId; /** @Column(length=255) */ private $lastName; /** @Column(length=255, name="user_firstname") */ private $firstName; /** * Bidirectional - Many users are geathered within one group (OWNING SIDE) * * @ManyToOne(targetEntity="\Entities\Group", inversedBy="user") */ private $group; /// --- }
<?php namespace Entities; /** *@Entity *@Table(name="group") */ class Group { /** *@Id *@Column(type="integer", name="group_id") *@GeneratedValue * */ private $groupId; /** @Column(name="group_name") */ private $name; /** * @OneToMany(targetEntity="\Entities\User", mappedBy="group") */ private $users; public function __construct() { $this->users = new \Doctrine\Common\Collections\ArrayCollection(); } }
In the following examples the id fields are set to $userId (mapped to user_id) and $groupId (mapped to group_id), but when it comes to generating the schema an error occures. The Doctrine CLI Tool doesn't work properly. When it generates the schema it fails to take into account the annotation blocks and just uses "id" instead of "group_id".
Let me explain it better. If we run the tool it will produce the following code
...
ALTER TABLE user ADD FOREIGN KEY (group_id) REFERENCES group(id)
instead of
ALTER TABLE `user` ADD FOREIGN KEY (`group_id`) REFERENCES `groups` (`group_id`);
Moreover using "group" as a name of the entity class will lead to numerous problems, because it's a reserved word in SQL. Even if we specify the quoatation forcibly using backticks it won't work:
/**@Table(name="`group`")*/ Class Group {
The quoatation won't be taken into account while generation the schema.
I'm enclosing the files I've tried to play with. Just try to generate the schema.
Fixed formatting, scheduled for 2.0.5