我在两个实体 Campsite 和 WeatherForecast 之间建立了 oneToMany 关联。在向露营地添加新预测之前,我想清除所有现有的。我尝试以下操作,但没有执行任何删除查询。任何人都可以对此有所了解吗?
$campsite = $campsiteRepository->find('campsite-2013-100006');
echo $campsite->getForecasts()->count() . PHP_EOL; //Outputs 7
$campsite->getForecasts()->clear();
echo $campsite->getForecasts()->count(); //Outputs 0
$em->persist($campsite);
$em->flush();
露营地实体
/**
* @ORM\OneToMany(targetEntity="AcsiCampsiteWeather\Entity\Forecast", mappedBy="campsite")
* @var \Doctrine\Common\Collections\ArrayCollection $forecasts
*/
protected $forecasts = null;
预测实体
/**
* @ORM\ManyToOne(targetEntity="AcsiCampsite\Entity\Campsite", inversedBy="forecasts", fetch="LAZY")
* @ORM\JoinColumn(name="relationID", referencedColumnName="relationID", nullable=false)
* @var \AcsiCampsite\Entity\Campsite $campsite
*/
protected $campsite = null;