考虑以下Symfony实体:
class Continent
{
/**
* @ORMId
* @ORMColumn(type="integer", name="id")
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORMColumn(type="string", length=20, nullable=true, name="text")
*/
private $text;
/**
* @ORMOneToMany(targetEntity="AppBundleEntityCountry", mappedBy="continent")
*/
private $countries;
/**
* Constructor
*/
public function __construct()
{
$this->countries= new DoctrineCommonCollectionsArrayCollection();
}
class Country
{
/**
* @ORMId
* @ORMColumn(type="integer", name="id")
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORMColumn(type="string", length=20, nullable=true, name="text")
*/
private $text;
/**
* @ORMOneToMany(targetEntity="AppBundleEntityCity", mappedBy="country")
*/
private $cities;
/**
* @ORMManyToOne(targetEntity="AppBundleEntityContinent", inversedBy="country")
* @ORMJoinColumn(name="continentt_id", referencedColumnName="id")
*/
private $continent;
/**
* Constructor
*/
public function __construct()
{
$this->cities= new DoctrineCommonCollectionsArrayCollection();
}
class City
{
/**
* @ORMId
* @ORMColumn(type="integer", name="id")
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORMColumn(type="string", length=30, nullable=true, name="text")
*/
private $text;
/**
* @ORMManyToOne(targetEntity="AppBundleEntityCountry", inversedBy="city")
* @ORMJoinColumn(name="country_id", referencedColumnName="id")
*/
private $country;
/**
* Constructor
*/
public function __construct()
{
}
我的问题是:
有没有办法使用注释将$continent成员添加到表示后退/间接关系(即城市所在国家/地区的大陆(的城市实体类中
如果无法使用注释,那么解决此问题的好做法是什么(例如自定义存储库?
我不知道
任何教义标准注释来做到这一点。
如果您的目的只是让大陆与该国相关,为什么不简单地这样做:
public function getContinent()
{
return $this->country->getContinent();
}