Get app_table table object by table ID

Good morning!

I am managing data using from the CSV builtin table export. For linked rows the export gives “#ROW[123,456]” or “#ROWS[[123, 789]]” where the first element in the linked row corresponds to the table ID and the second to the row ID in that table.

I would like to be able to access the corresponding table via app_tables.get_table_by_id(“123”).

Thanks,

Ty

4 Likes

I’ve noticed the same thing. As I understand it, however, this particular representation of row ids is subject to change without notice, so I’m reluctant to depend on it in any way.

I’d like to suggest a slightly different idea, one that does not depend on the internal structure of a row id. E.g.,

app_tables.get_table_by_row_id(s)

where s is any string containing a row id. In short, let Anvil pick it apart for you. That way, when the representation changes, it will be Anvil’s responsibility to keep this function working, not yours.

Would that work for you?

5 Likes

I agree with @p.colbert, but in the mean time you can see the row id with row.get_id() and (if I remember correctly the row id format) you can use app_tables.table_name.get_by_id('[123,456]') (no space after the comma) to get the row.

I have the row and row ID, I need the table_name from the row ID.

1 Like

Is there a way to get the Table associated with a specific Table ID these days?

You could brute-force it, I suppose.

For each table name, use search() to get a row. (If the table has no rows, then add one, temporarily.) From the row, get its id. Extract the first number from the id. Now you have a listing of table names and ids, and can look it up.

If you’re using accelerated tables there is a function
anvil.tables.get_table_by_id

5 Likes

Awesome!

I’ve added it to the documentation list.

I can’t see this anywhere in the API documentation.

Is there a lot of attributes/functions that aren’t in the documentation?