Skip to content

The associated query to multiple tables #300

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

Closed
JinJieGu opened this issue Dec 6, 2017 · 6 comments
Closed

The associated query to multiple tables #300

JinJieGu opened this issue Dec 6, 2017 · 6 comments
Labels
duplicate This issue or pull request already exists

Comments

@JinJieGu
Copy link

JinJieGu commented Dec 6, 2017

// Customer.java
@Entity
public class Customer {
 
    @Id public long id;
    public boolean male; 
    @Backlink
    public ToMany<Order> orders;
 
}
 
// Order.java
@Entity
public class Order {
 
    @Id public long id;
    public boolean isCash;
    public ToOne<Customer> customer;
 
}

If the tables like this, I want use the DataSubscription to observer the data which Customer is male and Order isCash? What should I do ?Thank you very much !

@greenrobot
Copy link
Member

Sounds like you are wanting to do two (separate) queries?

@JinJieGu
Copy link
Author

JinJieGu commented Dec 6, 2017

I want to get the customers(isMale) 's orders(isCash), so I don't know how to write the DataSubscription

@JinJieGu
Copy link
Author

JinJieGu commented Dec 6, 2017

Do objectBox support multiple table queries like SQL?

@greenrobot
Copy link
Member

At the moment we do not offer much convenience here for cases like yours (feature requests are pending).

This would be how you get the data, put this in some method:

long customerIds[] = customerBox.query().equal(Customer_.male, true).build().findIds();
List<Order> orders = orderBox.query().equal(Order_.isCash, true).in(Order_.customerId, customerIds).build().find();

Then you would subscribe to changes of those to classes using a general subscribe call:

boxStore.subscribe().observer(new DataObserver<Class>() { ...});

In your DataObserver implementation you should check if the class is either Customer or Order and in that case call your method triggering the method with the query.

This is not optimal and we are working on reducing the amount of required code, but it should work.

@jrcacd
Copy link

jrcacd commented Mar 8, 2018

We need the same for many-to-many query

@greenrobot-team
Copy link
Member

Please vote for #59.

@greenrobot-team greenrobot-team added the duplicate This issue or pull request already exists label Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants