Skip to content

Instantly share code, notes, and snippets.

@ornj
Created December 4, 2012 20:24
Show Gist options
  • Save ornj/4208313 to your computer and use it in GitHub Desktop.
Save ornj/4208313 to your computer and use it in GitHub Desktop.
Using fetch="EAGER" to cut down on trips to the database
<?php
namespace Acme\ContentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="Acme\ContentBundle\Entity\AbstractContentRepository")
* @ORM\Table(name="content")
* @ORM\HasLifecycleCallbacks
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"artwork"="Acme\ArtworkBundle\Entity\Artwork"})
*/
abstract class AbstractContent {
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
protected $type;
public function __construct() {
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace Acme\ArtworkBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Acme\ArtworkBundle\Entity\Date;
use Acme\ContentBundle\Entity\AbstractContent;
/**
* @ORM\Table(name="artwork")
* @ORM\Entity(repositoryClass="Acme\ArtworkBundle\Entity\ArtworkRepository")
* @ORM\HasLifecycleCallbacks
*/
class Artwork extends AbstractContent {
/**
* @var string $date
*
* @ORM\ManyToOne(targetEntity="Date", inversedBy="artwork", cascade={"persist"}, fetch="EAGER")
* @ORM\JoinColumn(name="date", referencedColumnName="id")
*/
private $date;
public function __construct() {
parent::__construct();
$this->type = 'artwork';
}
/**
* Set date
*
* @param Acme\ArtworkBundle\Entity\Intention $date
* @return Artwork
*/
public function setDate(\Acme\ArtworkBundle\Entity\Date $date = null) {
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return Acme\ArtworkBundle\Entity\Date
*/
public function getDate()
{
return $this->date;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment