Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Invalid
-
Affects Version/s: 2.0.7
-
Fix Version/s: None
-
Component/s: ORM
-
Security Level: All
-
Labels:
Description
I have 2 classes. Zone and Rotator.
Zone relates to Rotator as One-to-Many. And Zone COULD realte to Rotator as One-to-One. Here is code snippet:
class Zone
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="Rotator", mappedBy="zone", cascade={"persist", "remove", "merge"}, orphanRemoval=true)
* @ORM\OrderBy({"id" = "ASC"})
*/
private $rotators = array();
/**
* @var Rotator $mainRotator
*
* @ORM\OneToOne(targetEntity="Rotator")
* @ORM\JoinColumn(name="mainRotatorId", referencedColumnName="id")
*/
private $mainRotator;
/**
* @var int $mainRotatorId
*
* @ORM\Column(name="mainRotatorId", type="integer", nullable="true")
*/
private $mainRotatorId;
}
class Rotator
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var Zone $zone
*
* @ORM\ManyToOne(targetEntity="Zone")
* @ORM\JoinColumn(name="zoneId", referencedColumnName="id")
*/
private $zone;
/**
* @var int $zoneId
*
* @ORM\Column(name="zoneId", type="integer")
*/
private $zoneId;
}
When I delete only Zone - calculator works fine. But it fails if I delete entity Site, that relates to Zone as one-to-many (and have a lot of other raltions, so I don't write it here).
As I look through the code, I see CommitOrderCalculator doesn't distiguish mandatory many-to-one relation from optional one-to-one one.
PS this code hadn't been changed since 2.0, so this bug should be reproducable for master.
Your issue is because you have $zone and $zoneId pointing both to an association AND to a field.
Remove the $zoneId field (you can grab it by many different ways) and your issue should be solved.