Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessing sub collections from a Typesaurus Doc #134

Open
drewdearing opened this issue Jun 30, 2024 · 2 comments
Open

accessing sub collections from a Typesaurus Doc #134

drewdearing opened this issue Jun 30, 2024 · 2 comments

Comments

@drewdearing
Copy link

I have a nested collection db.

export const db = schema(($) => ({
  items: $.collection<Item>().sub({
    sub_items: $.collection<SubItem>(),
  }),
}));

When I access an Item Doc, I expect to be able to query the sub items directly from the item using some instance method.

const [items] = useRead(db.items.all().on);

items.map((item) => item.sub_items.all()...)

It looks like this is not currently supported, unless I'm missing something. I can do something like this, but I can see this getting very annoying to deal with in situations where I have a triple nested collections.

//get sub_item's items
db.items(subItem.data.item_ref.id).sub_items(subItem.ref.id).items.all();

It basically means I need to store the ref of every ancestor doc in my sub_item doc in order to access the sub_item's subcollection.

Please tell me I'm missing something.

@kossnocorp
Copy link
Owner

It looks like this is not currently supported, unless I'm missing something. I can do something like this, but I can see this getting very annoying to deal with in situations where I have a triple nested collections.

You're right. I planned to allow accessing doc/ref subcollections through sub property, but I never got to implement it.

It would look something like this:

item.sub.sub_items.all()

@drewdearing
Copy link
Author

item.sub.sub_items.all()

All I can say is that is exactly what I am looking for. Would be happy to look into it as well if I get the time. I can predict having to write out the db collection chain on every query will become quite ruthless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants