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 a many to one object #906

Open
pawnjester opened this issue Dec 2, 2019 · 1 comment
Open

Accessing a many to one object #906

pawnjester opened this issue Dec 2, 2019 · 1 comment

Comments

@pawnjester
Copy link

pawnjester commented Dec 2, 2019

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
Copy link
Author

@npurushe

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

1 participant