requery / requery

requery - modern SQL based query & persistence for Java / Kotlin / Android
Apache License 2.0
3.13k stars 245 forks source link

Accessing a many to one object #906

Open pawnjester opened 4 years ago

pawnjester commented 4 years ago

Question How can I query the categories of a product? I am trying to match the categories with the passed in the query.

Situation I want to be able to search for categories of products.

I have two tables for this:

interface Product { @Bindable @ManyToOne ProductCategoryEntity getCategory(); }

and interface ProductCategory { @OneToMany(mappedBy = "category", cascade = {CascadeAction.SAVE}) List<ProductEntity> getProducts(); }

I want to access the categories of products This is my approach Selection<ReactiveResult<ProductEntity>> productsSelection = mDataStore.select(ProductEntity.class); productsSelection.where(ProductEntity.OWNER.eq(merchantEntity)); productsSelection.where(ProductEntity.NAME.like(query)).or(ProductEntity.CATEGORY.like(query); productsSelection.where(ProductEntity.DELETED.notEqual(true));

This does not match the name of the category as I stated here productsSelection.where(ProductEntity.NAME.like(query)).or(ProductEntity.CATEGORY.like(query);

How can I go about getting the categories of a product as this is returning null What is the right approach to getting data from many to one relationships?

pawnjester commented 4 years ago

@npurushe