考虑以下Symfony实体:
class Continent
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="id")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(type="string", length=20, nullable=true, name="text")
*/
private $text;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Country", mappedBy="continent")
*/
private $countries;
/**
* Constructor
*/
public function __construct()
{
$this->countries= new \Doctrine\Common\Collections\ArrayCollection();
}
class Country
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="id")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(type="string", length=20, nullable=true, name="text")
*/
private $text;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\City", mappedBy="country")
*/
private $cities;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Continent", inversedBy="country")
* @ORM\JoinColumn(name="continentt_id", referencedColumnName="id")
*/
private $continent;
/**
* Constructor
*/
public function __construct()
{
$this->cities= new \Doctrine\Common\Collections\ArrayCollection();
}
class City
{
/**
* @ORM\Id
* @ORM\Column(type="integer", name="id")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(type="string", length=30, nullable=true, name="text")
*/
private $text;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Country", inversedBy="city")
* @ORM\JoinColumn(name="country_id", referencedColumnName="id")
*/
private $country;
/**
* Constructor
*/
public function __construct()
{
}
我的问题是:
有没有一种方法可以使用注解将$ continent成员添加到City Entity类中,该成员表示后向/间接关系(即城市所在国家/地区的大陆)
如果无法使用注释,什么是解决此问题的好方法(例如,自定义存储库?)
我不知道任何教义标准注释可以做到这一点。
如果您的目的只是为了使该大陆与该国家相关,那么为什么不干脆做一下:
public function getContinent()
{
return $this->country->getContinent();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句