I set up a simple User->Comment association in Doctrine, simple OneToMany (One User can write many Comments).
All works find, but i found a strange behavior of Doctrine. First some Code:
User Entity
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User extends EntityAbstract {
/**
* @var int
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue
*/
protected $_id;
/**
* @var \Doctrine\Common\Collections\Collection
* @ORM\OneToMany(targetEntity="Comment", mappedBy="TodayIsASunnyDay")
* ^^^^^^^^^^^^^^^^ WTF
*/
protected $_commentsAuthored;
public function __construct() {
$this->_commentsAuthored =
new \Doctrine\Common\Collections\ArrayCollection();
}
}
Comment Entity
/**
* @ORM\Entity
* @ORM\Table(name="comments")
*/
class Comment extends EntityAbstract {
/**
* @var int
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue
*/
protected $_id;
/**
* @var User
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*
*/
protected $_author;
}
In User, doctrine wants a mappedBy Attribute since its the inversed Side of the association. But as it seems, I can write anything I want as value. (the right value would be "user_id" i think?)
So, when is this value ever used or checked?