Yii Framework Forum: Problem with "LIMIT" argument in CDbCriteria - Yii Framework Forum

Jump to content

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

Problem with "LIMIT" argument in CDbCriteria Rate Topic: -----

#1 User is offline   csun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 19-May 10

Posted 02 July 2010 - 07:01 PM

I have a game application with a leaderboard that shows the highest scores.
I tried to increase the number of results shown in the leaderboard by changing the value of the "limit" parameter passed
in the CDbCriteria array

                  $high_scores_dp = new CActiveDataProvider('score',
                                    array('criteria' =>
                                        array('condition' => 'game_id = ' . $model->id,
                                              'order' => 'score desc',
                                              'limit' => 20,     //  <=== TRIED CHANGING THIS VALUE
                                             )
                                         )
                                  );


The original value of "limit" was 10, and I changed it to 20.
But after viewing the page, only 10 results were still shown.
I used the CFileLogRoute to view the SQL generated and the the query showed "LIMIT 10" still.

So I'm totally confused why I can't change the value of the "limit" arg.
Is there some kind of sql query caching going on?
Anyone have ideas?

Another thing I tried was modifying the data so it would return different results (different DB rows returned), but still only 10 rows were returned. I also turned off memcache, but still no difference. I also changed the "order" argument to sort by "ASC" instead of "DESC" to make sure the same query wasn't always being run. The results changed, but the limit was still 10.
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 03 July 2010 - 03:34 AM

Do you use pagination? I guess, it will override LIMIT with the configured pageSize.
0

#3 User is offline   csun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 19-May 10

Posted 03 July 2010 - 11:12 AM

View PostMike, on 03 July 2010 - 03:34 AM, said:

Do you use pagination? I guess, it will override LIMIT with the configured pageSize.


Hey Mike, thanks for your comment.
I wasn't explicitly using or not using pagination. But your comment led me to add the line below and now things are working. (This seems like a bad default behavior for Yii).

                  $high_scores_dp = new CActiveDataProvider('score',
                                    array('criteria' =>
                                        array('condition' => 'game_id = ' . $model->id,
                                              'order' => 'score desc',
                                              'limit' => 20,
                                             ),
                                   'pagination' => false            // <=== FIXED BY ADDING THIS LINE

                                         )
                                  );

1

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 04 July 2010 - 02:35 AM

Yii follows the "convention over configuration" paradigm. CActiveDataProvider was actually introduced to make working with sorting/pagination/filtering quick and painless. That's why by default this component has some sane default settings.
1

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