Yii Framework Forum: Condicional Y Orden En Find - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Condicional Y Orden En Find Rate Topic: -----

#1 User is offline   Jonathan Morales Salazar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 08-January 14

Posted 10 April 2014 - 04:08 PM

hola, necesito pasar un condicional a un método find y ordenarlo descendentemente por el id, pero no me sale ni con find ni con findAll, ¿alguna idea?

$pagos = Pagoparcialvariable::model()->find("formapagocontrato_id = $pagoforma->id", array('order' => 'id desc'));

0

#2 User is offline   Jonathan Morales Salazar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 08-January 14

Posted 10 April 2014 - 04:52 PM

Parece que no se puede, al final lo solucioné usando criteria:

$criteria = new CDbCriteria;
$criteria->select = array('numeropago');
$criteria->condition = "formapagocontrato_id IN ($pagoforma->id)";
$criteria->order = 'id desc';
$pagos = Pagoparcialvariable::model()->find($criteria);

0

#3 User is offline   a18327 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 14-August 13
  • Location:México

Posted 21 April 2014 - 10:48 AM

Find solo devuelve un model, FindAll devuelve un array de models, asi que en Find no tiene mucho caso ordenar(solo que quieras obtener la fila cuya columna x sea el mayor o el menor).
Ahora para ordenar es asi.
$pagos = Pagoparcialvariable::model()->findAll(array('condition'=>"formapagocontrato_id = $pagoforma->id",'order' => 'id desc'));

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users