mbouclas / loopback-ds-tree-mixin

Transform a loopback model into a tree using the Array of Ancestors pattern
MIT License
6 stars 4 forks source link

Apply filter on child nodes in asTree/AllTree API queries #16

Open haresh333 opened 5 years ago

haresh333 commented 5 years ago

Hi

I have started exploring this mixin. I would like to have following capability. Please advice how this can be achieved.

For example. I created hierarchy of catagories for books say Young Adult --> Action --> Adventure --> Fiction Young Adult --> Action --> Adventure --> Real Life --> Mythological

Each node is a Model called category. Each category has following relationship Category --> Has Many --> Books Book --> belongs to --> one category (for simplicity)

Note. books may belong to root node, parent node. Not just leaf nodes.

I can select any particular category and get list of books.

What I would like to do is, get list of all books for each category in one go.

The API asTree/AllTree should get me a tree of categories and embed in each category document, list of associated books by using 'Include' . This I want to achieve using single API as in my business use case, hierarchy of categories and corresponding items is small and finite. Hence I want to build an optimized way to query the data to provide better user experience by fetching all the items in advance.

The allTree API takes parameter which seems to apply Filter defining fields, where, include, order, offset, and limit ONLY ON roots node.

CAN THIS BE MODIFIED TO APPLY THE FILTERS ON CHILD NODES AS WELL? Particulary Scope {Include, where"} ??

Regards