Fetching fetch all categories where all items or sub_categories items are "veg" #333

Open
opened 2025-12-29 15:29:18 +01:00 by adam · 1 comment
Owner

Originally created by @techiesanjaypathak on GitHub (Jun 11, 2020).

My restaurant table structure is as follows:
MenuCategory
restaurant_id
category_id
category_name
items
sub_categories

                Either items or sub_categories will be present in the above table.

MenuSubCategory
ranking
sub_category_id
sub_caterory_name

MenuItem
item_id
item_name
item_price
item_type
<------- Can be "veg" or "non-veg"

Currently, I am fetching all the categories for a particular restaurant like this:
CoreStoreDefaults.dataStack.fetchAll(
From()
.where(format:"%K = %@", #keyPath(MenuCategory.restaurant_id), restaurant_id)
.orderBy(.ascending(.category_id))
)

And accessing subCategories by category?[section].sub_categories
and accessing items category?[section].items

How to fetch all categories where all items or sub_categories items are "veg"?

Originally created by @techiesanjaypathak on GitHub (Jun 11, 2020). My restaurant table structure is as follows: **MenuCategory** _restaurant_id category_id category_name items sub_categories_ Either items or sub_categories will be present in the above table. **MenuSubCategory** _ranking sub_category_id sub_caterory_name_ **MenuItem** _item_id item_name item_price item_type_ <------- Can be "veg" or "non-veg" Currently, I am fetching all the categories for a particular restaurant like this: CoreStoreDefaults.dataStack.fetchAll( From<MenuCategory>() .where(format:"%K = %@", #keyPath(MenuCategory.restaurant_id), restaurant_id) .orderBy(.ascending(\.category_id)) ) And accessing subCategories by category?[section].sub_categories and accessing items category?[section].items How to fetch all categories where all items or sub_categories items are "veg"?
adam added the enhancementquestion labels 2025-12-29 15:29:18 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Jun 12, 2020):

There is no built-in syntax in CoreStore for this yet, but you can use SUBQUERY expressions in the where() clause

@JohnEstropia commented on GitHub (Jun 12, 2020): There is no built-in syntax in CoreStore for this yet, but you can use SUBQUERY expressions in the `where()` clause
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#333