我想实现这种类型的关系:
SimpleUser 类必须有一个“语言”类属性,该属性应包含绑定到 UserLanguages 表中当前用户的所有 SimpleLanguage-s 的列表。
请看课程:
public class SimpleUser {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50)
*/
private $name;
// what do I type here? I want to have SimpleLanguage[] here
private $languages;
}
public class SimpleLanguage {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50)
*/
private $name;
}
public class UserLanguages {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
* @ORM\Column(name="user_id", type="integer")
*/
private $userId;
/**
* @var integer
* @ORM\Column(name="language_id", type="integer")
*/
private $languageId;
/**
* @var SimpleUser
*
* @ManyToOne(targetEntity="SimpleUser")
* @JoinColumn(name="userId", referencedColumnName="id")
*/
private $user;
/**
* @var SimpleLanguage
*
* @ManyToOne(targetEntity="SimpleLanguage")
* @JoinColumn(name="languageId", referencedColumnName="id")
*/
private $language;
}