我有两个实体广告1城市
一个广告属于许多城市
一个城市有很多广告
我需要一个解决方案来关联这两个实体,我的目标是:
从$ advert对象获取$ cities
从$ city获取$ adss
$ advert-> getCities()
$都市> getAdverts()
<?php
namespace Ligo\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping\ManyToMany;
/**
* Advert
*
* @ORM\Table(name="advert")
* @ORM\Entity(repositoryClass="Ligo\PlatformBundle\Repository\AdvertRepository")
*/
class Advert
{
/**
* @ORM\ManyToMany(targetEntity="City")
* @ORM\JoinTable(name="adverts_cities",
* joinColumns={@ORM\JoinColumn(name="advert_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="city_id", referencedColumnName="id")}
* )
*/
private $Cities;
&#13;
<?php
namespace Ligo\PlatformBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* City
*
* @ORM\Table(name="city")
* @ORM\Entity(repositoryClass="Ligo\PlatformBundle\Repository\CityRepository")
*/
class City
{
/**
* @ORM\ManyToMany(targetEntity="Advert", mappedBy="Cities")
**/
private $Adverts;
&#13;