tirithen
tirithen

Reputation: 3517

Symfony2 with Doctrine: Nested conditions for findBy

I'm trying to select only submissions that belongs to unlocked users (I'm using FOSUserBundle). Since I have a ManyToOne relationship on the submission entity, I figured that it might work to use nested conditions with findBy, it does not crash but gives me an empty result.

$submissions = $this->getDoctrine()
    ->getRepository('MyBundle:Submission')
    ->findBy(
        array(
            'author' => array(
                'locked' => false
            )
        ),
        array('createdAt' => 'DESC'),
        12
    );

Do I have to use query builder with joins for this to work? Something like the above would be so much cleaner code. It seemes to me that this would be a common problem for blog posts in a blog system and so on...

Upvotes: 0

Views: 1198

Answers (1)

Cyprian
Cyprian

Reputation: 11364

No you can't do such thing. But you will get even cleaner code if you move building query to a custom repository for Submission entity. For example the code will be look like:

$submissions = $this->getDoctrine()
    ->getRepository('MyBundle:Submission')
    ->fetchByUnlockedAuthor(12);

Where fetchByUnlockedAuthor would be a method in your custom repository.

Upvotes: 1

Related Questions