AR and Postgres Sorting

I can’t seem to figure out a way to sort records. I am using Postgres, and my ‘sort’ field criteria are either ignored or cause errors. I am looking for help in adding:

ORDER BY created DESC

to the call below.




$data = new CActiveDataProvider('content',

				array( 

					'criteria'   => array( 'condition' => $condition ),

					'pagination' => array( 'pageSize'  => self::PAGE_SIZE ) 

					)

				);



Also, is it possible that some of the ActiveRecord stuff is not yet implemented for Postgres? For example, I can make a condition such as ‘parent_id=42’, but I can’t use the method where you specify an array with ‘parent_id=:pid’ and another with ‘:pid’=>42. The latter method results in an error (“no such index 0”) when attempting to execute the SQL.

I figured out something that works:




$criteria = new CDbCriteria( array( 'condition' => $condition, 'order' =>'created DESC' ) );

$data = new CActiveDataProvider('content',

				array( 

					'criteria'   => $criteria,

					'pagination' => array( 'pageSize'  => self::PAGE_SIZE ) 

					)

				);



I am thinking there is a more compact way of doing it, with just arrays passed to the CActiveDataProvider() call though, right?

Okay, so I figured out what I was doing wrong. The "order" is a part of the "criteria" array, not a separate item at the top level.