Relationship sort

A place for users and developers of the Xataface to discuss and receive support.

Relationship sort

Postby 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?
ngms27
 
Posts: 30
Joined: Mon Nov 12, 2012 8:18 am

Re: Relationship sort

Postby 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'
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Relationship sort

Postby 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
 
Posts: 30
Joined: Mon Nov 12, 2012 8:18 am

Re: Relationship sort

Postby 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.
ngms27
 
Posts: 30
Joined: Mon Nov 12, 2012 8:18 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved