OneToOne
OneToMany
ManyToOne
use Doctrine\ORM\Mapping as ORM;
/**
* User
* @ORM\Entity
* @ORM\Table
*/
class User
{
/**
* 一个用户对应一个资料
* @OneToOne(targetEntity="Profile")
* @JoinColumn(name="profile_id", referencedColumnName="id")
* # user.profile_id = profile.id
*/
protected $profile;
/**
* 多个用户对应一个组
* @ManyToOne(targetEntity="Group", inversedBy="groups")
* @ORM\JoinColumn(name="group_id", referencedColumnName="id")
* # user.group_id = group.id
*/
protected $group;
}
/**
* Profile
* @ORM\Entity
* @ORM\Table
*/
class Profile
{
/**
* @OneToOne(targetEntity="User", mappedBy="profile")
*/
protected $user;
}
/**
* Group
* @ORM\Entity
* @ORM\Table
*/
class Group
{
/**
* 一个组对应多个用户
* @OneToMany(targetEntity="User", mappedBy="groups", cascade={"all"})
*/
protected $users;
}