Skip to content

Commit f849719

Browse files
author
Ivan Dlugos
committed
Box.remove support both object and ID argument
1 parent 49f6a0b commit f849719

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

objectbox/box.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ def get_all(self) -> list:
116116
finally:
117117
obx_bytes_array_free(c_bytes_array_p)
118118

119-
def remove(self, id: int):
119+
def remove(self, id_or_object):
120+
if isinstance(id_or_object, self._entity.cls):
121+
id = self._entity.get_object_id(id_or_object)
122+
else:
123+
id = id_or_object
120124
obx_box_remove(self._c_box, id)
121125

122126
def remove_all(self) -> int:

tests/test_basics.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ def test_box_basics():
8585
assert_equal(read, object)
8686

8787
# remove
88-
box.remove(object.id)
88+
box.remove(object)
89+
box.remove(1)
8990

90-
# check it's missing
91-
assert box.count() == 1
91+
# check they're gone
92+
assert box.count() == 0
9293
with pytest.raises(objectbox.NotFoundException):
9394
box.get(object.id)
95+
with pytest.raises(objectbox.NotFoundException):
96+
box.get(1)
9497

9598

9699
def test_box_bulk():

0 commit comments

Comments
 (0)