Page 1 of 1

Relationship sort

PostPosted: Tue Jan 15, 2013 11:03 am
by ngms27
I have a table Projects with a one to many relationship with notes.
I want the newest note added to appear on the top of the list.

I've added this to the notes.php file

function beforeHandleRequest(){
$query =& Dataface_Application::getInstance()->getQuery();
if ( !$_POST and $query['-table'] == 'notes' and !isset($query['-related%3Asort']) ){
$query['-related%3Asort'] = 'id desc';
}
}

However this doesn't work. Do you have any suggestions?

Re: Relationship sort

PostPosted: Thu Jan 17, 2013 9:23 am
by shannah
If you're looking at the notes relationship of a project, then $query['-table'] will be 'projects'. You should be checking for: @
Code: Select all
$query['-table'] == 'projects' and @$query['-relationship'] == 'notes'

Re: Relationship sort

PostPosted: Fri Jan 25, 2013 9:11 am
by ngms27
I have this in projects.php but it doesn't work:

function beforeHandleRequest(){
$query =& Dataface_Application::getInstance()->getQuery();
if ( !$_POST and $query['-table'] == 'projects' and $query['-relationship'] == 'notes' and !$query['-related:sort'] ){
$query['-related:sort'] = 'date desc';
}
}

Any ideas why not?
No errors just doesn't sort the records.

Re: Relationship sort

PostPosted: Fri Jan 25, 2013 9:58 am
by ngms27
I've created a __sql__ statement and used order by for the relationship and my issue is now resolved.