3

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
JERC
  • 1,584
  • 3
  • 17
  • 38

3 Answers3

8

Symfony 1.4 Actually can handle multiply fields in one go, but this is ridiculous how you should use this functionality

Doctrine::getTable('MtCheck')->findOneBy('idAndc_type', array($id,$type))

where table

CREATE TABLE `mt_check` (
  `id` int(11) NOT NULL,
  `c_type` int(11) NOT NULL,
  `c_ver` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`,`c_type`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

You can use 'And' or 'Or' exact, and no spaces before and after.

Radamanf
  • 477
  • 1
  • 6
  • 15
  • I think you can also write `findOneByidAndc_type` (or sth like that) instead of `findOneBy`. – j0k Oct 31 '12 at 16:48
4

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();
  }
j0k
  • 22,600
  • 28
  • 79
  • 90
2

Radanmanf's answer helped me to resolve easily my prob. According to the question, following should also work.

Doctrine::getTable('MtCheck')->findOneByIdAndCType($id,$type);

Note the difference here. No array() passed as parameter. Just the values.

I tried both methods and both worked for me.

Further explanation DQL: DOctrine Query Language: Magic Finders

Community
  • 1
  • 1
nilufer
  • 39
  • 2