Skip to content

request new function to get the childtable #69

@guinanlin

Description

@guinanlin

For example, Delivery Note and Delivery Note Item have a parent-child relationship.

I expect a function that can query the fields of the parent table Delivery Note and the child table Delivery Note Item at once.

I tried reading using something like the following, but I couldn't read the ChildDocType.

After carefully studying Frappe's logic for reading child table data, it should be similar to the following reading logic, note the parameter parent=Delivery%20Note

http://192.168.32.2:8001/api/resource/Delivery%20Item?&parent=Delivery%20Note&fields=[%20"name",%20"item_code",%20"qty"%20]&filters=[[%20"parent",%20"=",%20"MAT-DN-2024-00001%20"]]
*/
export const useFrappeCascadeGetDocList = <T=any, K=FrappeDoc<T>>(MainDocType: string, ChildDocType: string, mainArgs?: GetDocListArgs<K>, childArgs?: GetDocListArgs<K>, swrKey?: Key, options?: SWRConfiguration) => {

    const { url, db } = useContext(FrappeContext) as FrappeConfig;

   
    const swrResult = useSWR<T[], Error>(
        swrKey === undefined ? `${getRequestURL(MainDocType, url)}?${getDocListQueryString(mainArgs)}` : swrKey,
        () => db.getDocList<T, K>(MainDocType, mainArgs),
        options
    );

  
    const childSWRKey = swrResult.data ? `${getRequestURL(ChildDocType, url)}?${getDocListQueryString(childArgs)}` : null;

    
    const childSWRResult = useSWR(childSWRKey, () => db.getDocList(ChildDocType, childArgs), {
        ...options,
        revalidateOnFocus: false,
        shouldRetryOnError: false, 
    });

    return {
        mainDocs: swrResult,
        childDocs: childSWRResult,
    };
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions