Search code examples
symfony1doctrinefindby

Multiple findby in symfony doctrine


I need to know if there is a way to do something like this:

$customerClient = $clientTable->findByCustomerNumber($this->array_data[$rowIndex]['D']);
$customerClient = $customerClient->findOneByEmpCartera($portfolio);

I get this error message

Call to undefined method Doctrine_Collection::findOneByEmpCartera()

I need do 2 filter in $clientTable object table,

Any advice will be usefull to me.


Solution

  • You can't this way.

    A findBy* method always return a Doctrine_Collection. And a findBy* method need to be called from a Table object.

    You can do it in one custom findBy, in your ClientTable:

      // you may update relation and/or table name
      public function findOneCustomerByEmpCartera($customer_member, $portfolio)
      {
        $q = $this->createQuery()
          ->from('Client cl')
          ->leftJoin('cl.Customer cu');
          ->where('cl.customer_number = ? AND cu.emp_cartera', array($customer_member, $portfolio));
    
        return $q->limit(1)->execute()->getFirst();
      }