-
-
Save Ocramius/2242147 to your computer and use it in GitHub Desktop.
Offending Child Loading Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$family = loadEntity('Family', 1); // wrapper for entity manager | |
// verify that there are more than one child | |
echo "There are " . count($family->getChildren()) . " children"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Family relationship | |
* | |
* @ORM\Entity | |
* @ORM\Table(name="family") | |
* | |
*/ | |
class Family | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue | |
*/ | |
protected $id; | |
/** | |
* Father | |
* | |
* @ORM\ManyToOne(targetEntity="Person", inversedBy="ffamilies", cascade={"persist", "remove"}) | |
* @ORM\JoinColumn(name="fatherid", referencedColumnName="id") | |
*/ | |
protected $father; | |
/** | |
* The mother | |
* | |
* @ORM\ManyToOne(targetEntity="Person", inversedBy="mfamilies", cascade={"persist", "remove"}) | |
* @ORM\JoinColumn(name="motherid", referencedColumnName="id") | |
*/ | |
protected $mother; | |
/** | |
* The children | |
* | |
* @ORM\OnetoMany(targetEntity="Person", mappedBy="family") | |
*/ | |
protected $children; | |
public function __construct() { | |
$this->children = new ArrayCollection(); | |
} | |
// setters, getters | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* Profile for a person who will be included within a family tree | |
* | |
* @ORM\Entity | |
* @ORM\Table(name="person") | |
* | |
*/ | |
class Person | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue | |
*/ | |
protected $id; | |
/** | |
* @ORM\OneToMany(targetEntity="Family", mappedBy="father") | |
**/ | |
protected $ffamilies; | |
/** | |
* @ORM\OneToMany(targetEntity="Family", mappedBy="mother") | |
**/ | |
protected $mfamilies; | |
/** | |
* @ORM\ManyToOne(targetEntity="Family", inversedBy="children") | |
* @ORM\JoinColumn(name="familyid", referencedColumnName="id") | |
**/ | |
protected $family; | |
public function __construct() { | |
$this->ffamilies = new ArrayCollection(); | |
$this->mfamilies = new ArrayCollection(); | |
} | |
// setters, getters | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment