vidalbenjoe
vidalbenjoe

Reputation: 975

Removing data in ObjectBox based on Id

I would like to remove the data on my ObjectBox database in Android based on its Id. Is this correct?

Box<Cart> box = ObjectBox.get().boxFor(Cart.class);
    Cart order = box.get(id);
    box.remove(order);

Thank you

Upvotes: 1

Views: 2197

Answers (1)

Markus Junginger
Markus Junginger

Reputation: 7090

The remove method is overloaded and there are variants accepting the following arguments:

  • entity object
  • ID (long)
  • java.util.Collection objects
  • long... ids
  • T... objects

Thus, you can directly remove by ID like this:

box.remove(id);

For more details, please check the API docs of the Box class.

Upvotes: 2

Related Questions