Order_by using a link field

I had a table query that was using search and order_by to sortby multiple fields. Originally the “product_name” field was a text field and this order_by was working fine. After I updated the “product_name” field to be a link field, the order_by stopped working. I guess this is because the ‘product_name’ is now returning a row instead of text. How can I get my order_by back up and working again?

The tables are set up as follows:

app_tables.railcars:
railcar_number - text
shipment_id - text
product_name - link
seal_numbers - text

app_tables.products:
product_name - text

Query:

@anvil.server.callable
def query_railcar_management():
  table = app_tables.railcars.search(
    tables.order_by('spot', ascending=False),
    tables.order_by('product_name', ascending=True),
    tables.order_by('railcar_number', ascending=True)
  )
  return table

I don’t know of a link field in the data tables. Usually this would be a text field. Can you provide a clone link?

EDIT Sorry you mean a linked row field.?

Yes - a linked row field

I don’t know that there is a way to do this without the use of a lookup column

For example if your linked row has a column called name and this what you wanted to sort by, then create a name column in your ‘rail car’ table called name with that value and then sort using that text column.

This would make a nice Feature request though if it hasn’t already been done.

You can’t use a linked table column for sorting.

If you are completely consuming the iterator, that is if you are using all the rows returned by the search, then you can sort them in memory with the sorted python function.

Using the sorted function with the standard tables could be slow, because it will trigger a round trip to the database server per linked row, while with the accelerated tables it should be very fast, because you can cache all the linked fields during the search.

Thank you @stefano.menci, this is the answer that I needed.