سؤال

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.

هل كانت مفيدة؟

المحلول

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();
  }

نصائح أخرى

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.

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top