tag_rows=app_tables.tags.search(name=q.any_of('tag_x', 'tag_y')) # or use * notation
tag_rows=[[r] for r in tag_rows]
projs=app_tables.projects.search(tag_links=q.any_of(*tag_rows))
The clone link is no longer valid so I couldn’t do more homework on my own.
I believe that I’m trying to do a similar query against a multi-row linked column. In my Pricing table, an entry/row can be valid for multiple Products (the multi-row linked column). I’d like to search/query the pricing table by one or more of those Products and get back all matching rows. If any of the products I’m searching for are attached to that Pricing row, I want the results.
This works if I’m only trying to search for one product: app_tables.pricing.search(Products=["Stantt MTO"])
However, trying to search for results that match multiple products does not work–It doesn’t return any rows. app_tables.pricing.search(Products=["Stantt MTO", "5-Pocket"])
See the picture for more of a visual of what the data looks like. I’ve substituted the Product row with the values shown in the screenshot to make this easier to follow.
This also doesn’t return any results: app_tables.pricing.search(Products=q.any_of(*["Stantt MTO", "5-Pocket"]))
Any ideas on how to modify my query to get the relevant rows?
Sorry, I had a syntax error in my last example, unpacking the list with q.any_of still doesn’t seem to work on linked rows. This is the error received when trying to do that:
TableError: "Column 'Products' can only be searched with a liveObjectArray (not a Row from 'Products' table) in table 'Pricing'"
Sorry, I should have taken a closer look at your table definition. Yes, a value in column Products is essentially a list of database table rows.
You can search using a “link to multiple rows” column. If you pass a list of row objects to search(), it will return only rows that link to all of those rows. (If you specify multiple rows, the order doesn’t matter - it matches anything that links to all of them.)
Unfortunately, this does an “all of” match. So you’ll need to build up a set of “any of” matches by doing it the long way: first create a list of matching products, then looping over each product in the list, to collect its matching Pricing rows.
Values in Multiple Link columns are represented as lists in Python. This means you need to query your Pricing table with a list of rows from your Products table:
# Construct a list of lists, each containing a row from the Products table
rows=[[r] for r in app_tables.products.search(name=q.any_of("Stantt MTO", "5-Pocket"))]
print(rows)
# Unpack the list of Product rows into your query against the Pricing table
matching_prices=app_tables.pricing.search(products=q.any_of(*rows))
This is equivalent to:
stantt_row = app_tables.products.get(name=("Stantt MTO"))
pocket_row = app_tables.products.get(name=("5-Pocket"))
# Query your Products table with Product rows represented as Python lists
matching_prices=app_tables.pricing.search(products=q.any_of(
[stantt_row],
[pocket_row]
))