Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Forked from ssmusoke/gist:2241826
Created March 29, 2012 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/2242147 to your computer and use it in GitHub Desktop.
Save Ocramius/2242147 to your computer and use it in GitHub Desktop.
Offending Child Loading Code
<?php
$family = loadEntity('Family', 1); // wrapper for entity manager
// verify that there are more than one child
echo "There are " . count($family->getChildren()) . " children");
<?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
}
<?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