Problem with sorting on a related Foundset

Hi all,

I am sorting a related Foundset based on a Field(Integer).

tbl_a_to_tbl_b.sort('tbl_a_to_tbl_b.company_id asc');

tbl_a_to_tbl_b - Is a Relation

I am displaying all the related records in a Table View.
But when I am executing the above code it is giving the wrong order. But when I am clicking the Header of the Field(company_id), It is giving the correct result.

But the correct sort of records can’t be achieved by the above code.

Am I missing some thing?

Is there any work around?

Rather It is working If I am sorting on the table on which the Field (company_id) is based upon.

forms.tbl_b.controller.sort('company_id asc');

Can’t be the columns are sortable over a relation?

If you use [relation].sort(), you’re already working through the relation, so you don’t need to specify it again when addressing the field names:

tbl_a_to_tbl_b.sort('company_id asc');

Hi Joas, Ars

I have the same problem. I can’t get a column sorted by a relationship!

connections_departing_place_terminated_by_stations.sort('name asc');

Joas

I have a second problem: I like to make an initial sort. I would like to sort the same attribut (name) via 2 different relationships. In the Property Editor window, when double clicking on the InitialSort property on the forms, the relationship is NOT shown, only the attribute. If I like to make an initial sort like

connections_departing_place_terminated_by_stations.sort(‘name asc’);
connections_arriving_place_terminated_by_stations.sort(‘name asc’);

It just doesn’t work! I assume it’s a bug, is it?

Best regards, Robert

Joas

First part is the wrong code for what I wanted to do.

Correct code is:

controller.sort('connections_departing_place_terminated_by_stations.name');

It also works for the same attribute via 2 relationships (what I would like to do in Initial Sort!)

Code then looks like this:

controller.sort('connections_departing_place_terminated_by_stations.name, connections_arriving_place_terminated_by_stations.name');

Initial Sort remains a problem. How to do in Initial Sort what I achieve with the above code?

Best regards, Robert

Hi Joas,

Joas:
If you use [relation].sort(), you’re already working through the relation, so you don’t need to specify it again when addressing the field names:

tbl_a_to_tbl_b.sort('tbl_a_to_tbl_b.company_id asc');

Yep, I have the relation, but i want to sort the related records(filtered by the same relationship) based on a Field of the table on which the relationship is based upon.

By using the below code.

tbl_a_to_tbl_b.sort('tbl_a_to_tbl_b.company_id asc');

But, It is not sorting the record :( .

Relationship is from the Table : tbl_a to Table : tbl_b
The Field(company_id), on which i want to sort the records, is from tbl_b.

Hope, it is clear to you guys.

How can I do the same, or it is a Bug?

Aah, that will work if we sort the real field not through the related Field. :)

This will solve the issue.

tbl_a_to_tbl_b.sort('company_id asc');

ars:
Aah, that will work if we sort the real field not through the related Field. :)

This will solve the issue.

tbl_a_to_tbl_b.sort('company_id asc');

That’s what I was telling you, but you edited my post when quoting :)

Robert Huber:
Initial Sort remains a problem. How to do in Initial Sort what I achieve with the above code?

It is true that you can’t select the same field of the same table more than once in the initialSort dialog. You should do a feature request if you want this.
For now you can execute your code in the onLoad method to get the same result.

Hi Joas

Yes, I need that functionality, so I will make a feature request. The use of an onLoad method is as you say for now a workaround.

Thanks and best regards, Robert

Robert Huber:
Initial Sort remains a problem. How to do in Initial Sort what I achieve with the above code?

It is true that you can’t select the same field of the same table more than once in the initialSort dialog. You should do a feature request if you want this.
For now you can execute your code in the onLoad method to get the same result.[/quote]