Yii Framework Forum: AR and Postgres Sorting - Yii Framework Forum

Jump to content

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

AR and Postgres Sorting Rate Topic: -----

#1 User is offline   queej 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 04-February 10

Posted 07 February 2010 - 02:09 PM

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.
0

#2 User is offline   queej 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 04-February 10

Posted 07 February 2010 - 02:19 PM

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?
0

#3 User is offline   queej 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 04-February 10

Posted 07 February 2010 - 04:21 PM

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.
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