I have a table that references itself in a one to many relationship, i.e. each row can be related to plenty of rows in the same table.
I need to find all related rows to the row selected by the user. here is what I tried
for table_accessory in app_tables.accessories.search():
for accessory in table_accessory['requires']: # here is where the error points to.
if accessory_id == accessory.get_id():
self.add_accessory(accessory.get_id())
yet I get an error
TypeError: 'NoneType' object is not iterable
at order_mainframe, line 43
I would rather be able to do a search on related contains accessory_id
As @p.colbert says, your second loop is trying to iterate over a None.
I would suggest just searching for the target row (based on the ID derived from the user’s selection), and using that row as a filter in your accessories table.
In other words,
grab the single row that corresponds to accessory_id (let’s call it “target_row”)
return rows from table_accessory where the requires columns contains “target_row”
target_row=app_tables.accessories.get(accessory_id='1')
# notice that you can pass a list to search within a multi-linked row
related_to_target=app_tables.accessories.search(linked_accessories=[target_row])
Here is what my self-referencing table looks like: