Pagination ordering of associated models

A "Ticket" hasMany "Options"

I want to paginate my data such that I can (in the view) show each a row of:


[ Ticket | opt 1 |       | opt 3 ]
[ Ticket | opt 1 | opt 2 | opt 3 ]
[ Ticket |       | opt 2 | opt 3 ]

etc. Some options may be present some may not.

To be able to accomplish as much of this in the model/controller as possible, I need to pass some order to the "options" model (and possibly some grouping), and I can't seem to figure that out!


Array
(
    [Ticket] => Array
        (
            [id] => xxxxx
            [name] => my ticket
        )
    [Option] => Array
        (
            [0] => Array
                (
                    [id] => xxxxxxx
                    [optionnumber] => 5
                    [val] => no
                )
            [1] => Array
                (
                    [id] => xxxxxxx
                    [optionnumber] => 2
                    [val] => tuesday
                )
            [2] => Array
                (
                    [id] => xxxxxxx
                    [optionnumber] => 5
                    [val] => something
                )
        )

)

as you may be able to see, the options arrays are not sorted by their ID, which I'd like. Further more, it would be even better if instead of an indexed array, the options array index was the id (I think grouping may acheive this...) but how do I get the optinos through to the associated model? so far I've tried things like:


$this->paginate = array(
    'Ticket'  =>array('limit' => 20,'fields'=>array('Ticket.*')),
    'Option'  =>array('order'=>array('Option.optionnumber'=>'asc')));

Asked by twistedpear, on 28/1/10

1 Answer

I think the correct syntax for order is much more like:


'Option' => array( 'order' => array('Option.optionnumber ASC')));

Also if you want to have the id as array key for the Option array, you will have to use Set::combine()

Pierre

Answered by real34on 29/1/10

<< previous next >>

Your Answer

You can use Creole Wiki Syntax to format your text.

Tagged with

Rating

0

Viewed

295 times

Last Activity

on 29/1/10