I'm starting out with doctrine2. So, I'm taking the following example, to understand how to do annotations for table relationship, for example:
-------- the tab开发者_Python百科les
USER id username group_id
GROUP id name
A given user, is part of a group (admin, member). For example, john is admin peter is member
<?php
/** @Entity */
class User
{
// ...
/**
* @ManyToOne(targetEntity="group")
* @JoinColumn(name="group_id", referencedColumnName="id")
*/
private $group;
}
/** @Entity */
class group
{
}
?>
I would like to understand if this is correct ?
Thanks for looking!
Thats correct as it is.
You could even ommit the @JoinColumn Statement as it will default to this values.
If you want a bidirectional relationship you also have to set the relationship on the group class like this:
@OneToMany(targetEntity="User", mappedBy="group")
private $users;
精彩评论