Assigning descending order to related records

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

Assigning descending order to related records

Postby sworden » Mon Sep 17, 2012 11:22 am

I found this article pertaining to assigning order to related records:
http://xataface.com/documentation/how-t ... ed-records

Andthe code works just fine, but how do I get the records to show up in descending order? Here is my code:
Code: Select all
[transcripts]
transcripts.APPLICANTS_ID = "$APPLICANTS_ID"
metafields:order = "transcripts.TRANSCRIPTS_DATE"
sworden
 
Posts: 44
Joined: Thu Feb 16, 2012 9:05 am

Re: Assigning descending order to related records

Postby shannah » Mon Sep 24, 2012 9:25 am

The metafields:order isn't really intended to be used this way. It is intended to be a numeric field that will be updated automatically to reflect the user assigned ordering of records. This column would then be the default sort order.

That said, your example will still result in a default sort on your date column... it just won't behave properly when the user tries to manually reorder the records. Because this wasn't the intended usage, there isn't a "descending" or other simple directive to cause it to sort in reverse.

There are two possible solutions to your problems.

1. Manipulate the query inside the application delegate's beforeHandleRequest() method to add the appropriate GET parameter to cause the records to be sorted descending on that column. (Try manually sorting the records on a column and take a look at the GET parameters in the resulting request to see how Xataface handles this and you'll know what parameter needs to be added).

2. Create a grafted field on the related table that is calculated such that it has a lower value for more recent dates and a higher value for older dates. Then use the metafields:order directive on this field.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Assigning descending order to related records

Postby sworden » Thu Nov 01, 2012 8:41 am

Thanks!

I've created a calculated field by adding this to my dates.php file. It creates a negative number, with the more current date having a lower value than an older date. There is probably a better way to do this, but it works:
Code: Select all
#This updates the DATES_SORT field.
mysql_query("UPDATE dates SET DATES_SORT = 100-STEP_DATE");

And in my relationships.ini file I now have this code to sort based on the calculated field, DATES_SORT:
Code: Select all
[progress]
dates.APPLICANTS_ID = "$APPLICANTS_ID"
metafields:order = "dates.DATES_SORT"

How do I get the DATES_SORT field to be hidden in all views? I'm the only one who's ever going to view the field, and I can do that in phpMyAdmin.
sworden
 
Posts: 44
Joined: Thu Feb 16, 2012 9:05 am

Re: Assigning descending order to related records

Postby shannah » Thu Nov 01, 2012 8:49 am

Code: Select all
visibility:list=hidden
visibility:browse=hidden
visibility:find=hidden
widget:type=hidden
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Assigning descending order to related records

Postby sworden » Thu Nov 01, 2012 9:29 am

Thanks! I had tried a few of those, but not all of them. That did it.
sworden
 
Posts: 44
Joined: Thu Feb 16, 2012 9:05 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 23 guests

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