Dataset filter by user login to a table with reference field

I have a data collection named, ‘Children’. The collection has a ‘Reference’ field that references ‘Site Members’ collection. Basically ‘Children’ collection has has the email of their parents that is in ‘Site Members’. Parent’s are the only ones that can register on the website.

I want a dataset that would return the Children’s data when the Parent Log’s in and clicks on ‘Children’.

  1. Option one: I have a dataset that connects to ‘Children’, when I try to add a Filter based on parent’s id, I get the following error “None of your current datasets are valid for this filter.”

  2. Option two: Filter based on ‘Owner’ is User: Logged-in user. Nothing comes back.

Any ideas?

You need to use code for that.
You can create an afterQuery hook for the Children collection to retrieve their parentId (you’ll need to have there .include() ).
Something like:

//backend/data.js
import wixData from 'wix-data';
export function Children_afterQuery(item, context) {
    retrun wixData.query(Children)
    .eq("_id", item._id)
    .include("parents")
    .find()
    .then(r => 
    if(r.items.length > 0){
    item.parents = r.items[0].parents;
    }
    return item;
    })
}

and in the front end use code to filter based on the id;

There’re other ways to it, but they all need code.

thank you

Hello J.D. Thank you very much for the reply. Could you please also share how the code would look in the front end (to filter based on the id)