Yii: Ajax sorting on STAT relations


/ Published in: PHP
Save to your folder(s)

When setting up the AJAX click to sort links for your index pages, it's nice to be able to sort on STAT and related data.

To get related data sorting in my CListView, I ended up having to forget about using "together" and "with" in my search function, and instead let everything lazy load. The number of queries explode, which sucks.

For handling your STAT relations, you can manually write SQL that runs when the sorting links are clicked. So this is pretty much duplicate code and sloppy, but it works.

The query below recreated this relation that exists on the model:
<code>
'followersCount'=>array(self::STAT,'GraphEdge','end','condition'=>'status=1'),
</code>

The naming here doesn't matter, the relation and sortable attribute are unfortunately independent. This was written for CListView but probably works with CGridView as well.
Don't forget to add followers_count to your List View's sortable attributes array.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.