I have an issue where I would like to use use the first entity I queried to load it's associated one to many entities. The issue I'm having is I would like to limit the query for "$campaignLogs" to "status" == "public"
The example below does not work, but shows what I would like to do. I found out already that you can't use where() on an array collection as it's already equivalently set or processed the query.
$em = $this->getDoctrine()->getManager();
$campaign = $em->getRepository('STLDevRPGBundle:Campaign\Campaign')->findOneByTitle($slug);
// This is what doesn't work, I have to change the "get" somehow
// or does this have to be a custom repository function?
$campaignLogs = $campaign->getCampaignLogs()->where(array("status = 'public'"));
You could add an optional parameter to your already existing custom method. Do something like this:
public function findOneByTitle($slug, $status = null)
{
$qb = $this->createQueryBuilder('c');
$qb->select('c');
->where('c.title = :title')
->setParameter('title', $slug);
if ($status !== null) {
$qb->join('c.campaignLogs', 'l');
$qb->where('l.status = :status')
->setParameter('status', $status);
}
return $qb->getQuery()->getSingleResult();
}