Relationship sort

Archived from the Xataface Users forum.

ngms27 — Tue Jan 15, 2013 11:03 am

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?


shannah — Thu Jan 17, 2013 9:23 am

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'

ngms27 — Fri Jan 25, 2013 9:11 am

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.


ngms27 — Fri Jan 25, 2013 9:58 am

I’ve created a __sql__ statement and used order by for the relationship and my issue is now resolved.