in symfony2.5 with doctrine2.x i try to set a paginator as described on the doctrine documentation
I have a oneToOne relation between article and topten
/**
* Article
*
* @ORM\Table(name="article", indexes={@ORM\Index(name="idx_title", columns={"title"})})
* @ORM\Entity(repositoryClass="My\TestBundle\Entity\ArticleRepository")
*{
class Article
{
/**
* @var integer
*
* @ORM\Column(type="bigint", name="id")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
// ...
/**
* @ORM\OneToOne(targetEntity="My\TestMobileBundle\Entity\Topten", mappedBy="article")
*/
protected $topten;
public function __construct() {
$this->topten = new ArrayCollection();
}
}
Topten Entity:
/**
* Topten
*
* @ORM\Table(name="topten", indexes={@ORM\Index(name="article_id_idx", columns={"article_id"})})
* @ORM\Entity(repositoryClass="My\TestMobileBundle\Entity\ToptenRepository")
*
*/
class Topten
{
/**
* @var integer
*
* @ORM\Column(type="bigint", name="id")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
//...
/**
* @ORM\OneToOne(targetEntity="My\TestBundle\Entity\Article", inversedBy="topten")
* @ORM\JoinColumn(name="article_id", referencedColumnName="id", unique=true)
*/
protected $article;
}
Controller:
$dql = "SELECT a from MyTestBundle:Article a";
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery($dql)
->setFirstResult(0)
->setMaxResults(20);
$articles = new Paginator($query, $fetchJoinCollection = true);
foreach($articles as $article)
{
echo $article->getTitle() . "<br/>\n";
}
//...
Doctrine now does 21 Mysql Queries.
Everytime i print the title, it does the Query:
SELECT
t0.id AS id1,
//...
FROM
topten t0
WHERE
t0.article_id = ?
What am I doing wrong or how can I stop this behavior?