I have two models:
class Store extends AppModel
{
        var $name = 'Store';
        var $belongsTo = array('Storeregion');
 }
class Storeregion extends AppModel
{
        var $name = 'Storeregion';
        var $hasMany = 'Store';
}

A region can have many stores.  Here is an example:
Array
(
 [0] => Array
        (
            [Storeregion] => Array
                (
                    [id] => 1
                    [name] => California
                )

            [Store] => Array
                (
                    [0] => Array
                        (),
                    [1] => Array
                        (),
                    [2] => Array
                        (),
                    [3] => Array
                        (),
                )
        }
 [1] => Array
        (
            [Storeregion] => Array
                (
                    [id] => 2
                    [name] => CTX
                )

            [Store] => Array
                (
                    [0] => Array
                        (),
                    [1] => Array
                        (),
                    [2] => Array
                        (),
                    [3] => Array
                        (),
                )
        }


so your paginate would be something like :

        var $paginate = array(
                                'Store' => array ('limit' => 25, 'order' =>
array('Store.name' => 'asc')) ,
                                'Storeregion' => array ('limit' => 25, 'order' 
=>
array('Storeregion.name' => 'asc'))
                            );

your view would be something like:

<?php echo $paginator->sort('Name', 'Store.name');?></th> etc....

    but you CAN NOT do this

<?php echo $paginator->sort('Storeregion', 'Storeregion.name');?></th>

 Why ?

controller:
function view_stores function() {$data = $this->paginate('Store');}

now i've come up with a way to modify it so that you examine $this-
>params["named"]["sort"] and get the model name out of it. thats easy
but then you have a problem in your view

--View problem

the problem is this ...
here is the store data <?php foreach($data as $store): ?> .... <td><?
php echo $store['Storeregion']['name']; ?></td> <td><?php echo
$store['Store']['storenumber']; ?></td>

now suppose if they want to sort by region Storeregion.name the issue
now becomes that your data will look like see above. Some regions will
have 5 stores, or 50 stores and it will output all of it even though
you set paginate too 'Storeregion' => array ('limit' => 25,
'order' ...

the reason why is that it is showing you only 25 regions , but a
region may have 5 stores or 50 stores
so then you're screwed and can't offer sorting by region.

Is there a solution to this ?

thanks.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to