findBy() all records with two conditions

Asked

Viewed 767 times

0

I’m trying to work with findBy() in an application made in Symfony2. I would like to put two conditions on Findby or mix with Where if possible, but am not getting.

$properties = $em->getRepository('PropertyBundle:Property')->findBy(array(),array('name' => 'ASC'));

I’d like to include the conditions active = '1' to choose only records that contain active(active) status.

$properties = $em->getRepository('CitraxPropertyBundle:Property')->findBy(array(),array('name' => 'ASC'),array('active' => 1));
  • Why the first array of the findBy is empty?

1 answer

3

Here are some examples of the Doctrine documentation itself. Doctrine’s website session 7.8.2. By Simple Conditions site

    <?php
// $em instanceof EntityManager

// All users that are 20 years old
$users = $em->getRepository('MyProject\Domain\User')->findBy(array('age' => 20));

// All users that are 20 years old and have a surname of 'Miller'
$users = $em->getRepository('MyProject\Domain\User')->findBy(array('age' => 20, 'surname' => 'Miller'));

// A single user by its nickname
$user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb'));

The official symfony documentation also has some examples Symfony documantation that talks about findby

This example is in the link above

    // query for one product matching by name and price
$product = $repository->findOneBy(
    array('name' => 'foo', 'price' => 19.99)
);

// query for all products matching the name, ordered by price
$products = $repository->findBy(
    array('name' => 'foo'),
    array('price' => 'ASC')
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.