How do I avoid the ‘N+1 queries’ problem when I add a field which represents a 2nd degree relationship, in a collection?
My DB has 3 models: an item, a vendor, and a vendor category.
For example, a “Table” from “Ikea”, which is a “Furniture company”.
Item and Vendor has a one-to-many relationship, and so do Vendor and Vendor Category.
This means that every item has exactly one Vendor Category. In Forest Admin, I want to add a ‘Vendor Category’ column to the “Items” collection.
One way I found to implement this, was to add a smart field that fetches the correct Vendor Category from the DB, for every item. However, this results in N calls to the DB (where N is the number of items presented in a page).
Is there a way to present this column, that does not involve N+1 queries? Thanks!