The-Commit-Company / frappe-react-sdk

React hooks for Frappe
https://frappe-react.vercel.app
MIT License
110 stars 36 forks source link

Support for Child table data on useFrappeGetDocList #9

Closed saleemdev closed 1 year ago

saleemdev commented 1 year ago

This is one sleek library @nikkothari22 , thanks on behalf of the entire world.!

Have you explored on how to add support for child table field data in the same query? (avoiding the N+1 problem and all that)

Please let me know if that is possible and if I might help improve the library!

nikkothari22 commented 1 year ago

Hey @saleemdev ,

Thank you, and I'm glad you're finding this library useful.

AFAIK, Child tables can be fetched via the standard API's (getDoc). I haven't tested this though. But since they use the standard REST API's in Frappe, they should be able to fetch a list of child table items. Let me know a specific use case so that I can help you.

In case you want to do something complex, I would recommend creating custom API's and then calling those API's via useFrappeGetCall. (I don't think the documentation is upto date. I'll fix it).

saleemdev commented 1 year ago

@nikkothari22 Hi, thankyou for your response!

I had actually just had gotten GET API call to work by following the documentation on the code.

I've made a pull request on the updated documentation, if that is okay ;)

You're right, in fact even frappe.get_list , frappe.get_all and frappe.get_doc do not return child tables so you have to use frappe.db.sql("sql_query_str", as_dict=1) if you want to get past the N+1 problem.