Monday, October 5, 2009

paginator, containable -> sort() does not work for not directly related fields

Hello,

I have a very nested belongsTo/hasMany structure of my models:
A belongsTo C
B belongsTo C
C belongsTo D
D belongsTo E
F belongsTo E
G belongsTo E

In E/index I want to list all E with the respective titles of all
related models.

EsController looks like this:
##################################
var $paginate = array(
'limit' => 20,
'contain' => array(
'D' => array(
'fields' => array('D.title','D.id','D.C_id'),
'C' => array(
'fields' => array('C.title', 'C.B_id','C.A_id','C.id'),
'A' => array(
'fields' => array('A.title','A.id')
),
'B' => array(
'fields' => array('B.title','B.id')
)
)
),
'G' => array(
'fields' => array('G.title','G.id')
),
'F' => array(
'fields' => array('F.title','F.id')
)
)
);

function index() {
$data= $this->paginate('E');
$this->set('data', $data);

##################################


and E/index.ctp contains sort functions like
###################################
<th><?php echo $paginator->sort('id','id');?></th>
<th><?php echo $paginator->sort('A','A.title');?></th>
<th><?php echo $paginator->sort('B','B.title');?></th>
<th><?php echo $paginator->sort('C','C.title');?></th>
<th><?php echo $paginator->sort('D','D.title');?></th>
<th><?php echo $paginator->sort('E','E.title');?></th>
<th><?php echo $paginator->sort(('F','F.title');?></th>
###################################


The problem is that sorting with $field = 'D.title', 'F.title' and
'G.title' work,
but $field = 'C.title', 'B.title' and 'A.title' do not.

I am afraid this is because C, B and A are not directly related to
model E, whereas D, F and G are.
Is there a way of change $keyin paginator::sort($title,$key) so that
cakephp knows which fields to sort or any other possibility to make
cakephp know what to do?

Thanks!
Melanie
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: