'Fastapi pydantic related schema response to be filtered by column

I am using fastapi pydantic schema for get request apis to invoice and its corresponding items. The api is working fine but considering all the related rows of items with invoice_id. But I want the foreign key related data to be filtered based on some column. Like where is_active == True, consider only those invoice item rows.

{
   'id': 1
   'invoice_number': 1
   'item_name': 'this is invoice one'
   'invoice_items': [
      {'invoice_id': 1, 'item_name': item one, deleted_at: None},
      {'invoice_id': 1, 'item_name': item two, deleted_at: None},
      {'invoice_id': 1, 'item_name': item three, deleted_at: None}
   ]
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source