Hi @nratner,
You’re actually really close! If you’re searching a data table for a particular column value, you need to search with a value of the right type. In this case, as you’re searching the category
column of app_tables.anomaly_category_and_type
, which is a link to a row from app_tables.anomaly_category
, you should pass in the actual row object to search()
.
I’ve modified your example so it works:
https://anvil.works/ide#clone:OFZKMHNUEHYXS3KS=WKLUFIWGQNA7AMHLYSUN43VO
I made the following changes:
-
When the server functions return item lists for DropDowns, I return tuples of
(<string label>, <actual value>)
. The DropDown will display the label string, butselected_value
will be the actual value (in this case, the row object itself). -
This means that when we’re calling
anomaly_type_group()
, we’re passing in an actual row from theanomaly_categories
table - not just the string from its first column. This means we can search correctly in the many-to-many table. -
I also cleaned up a couple of tiny bugs (eg you’d clearly renamed
self.anomaly_type_choice
since you wrote line 23 of Form1, so I changed it :). You also didn’t have thechange
event wired up for theanomaly_category_choice
dropdown, so I did that for you. I’m pretty sure you would have fixed these two bugs very quickly once you had the tables stuff sorted.)
I also have one recommendation – it will probably be helpful if you rename the first column of the “Anomaly Category” and “Anomaly Type” tables. I like to call that column 'name
'`. This makes it clear in your code whether you’re referring to a category (ie a row from that table) or the name of a category (a string). This helps with problems like the one you had here.
Here’s a version of that app with those columns renamed, to show what I mean:
https://anvil.works/ide#clone:2Y3MX4JXGRTF3CMP=EJOVTKBQCXWP6T25LU3ICI5X
I hope that helps! Please do keep asking questions (and thank you to everyone else who’s been chipping in!)