cos-archives / modular-odm

A database-agnostic Object-Document Mapper for Python.
Apache License 2.0
13 stars 18 forks source link

Remove removes all objects #97

Open chrisseto opened 10 years ago

chrisseto commented 10 years ago

Assumptions we have a stored object called tag

len(tag.find())  # 20
t = tag.find()[0]
t.remove()
len(tag.find()) # 0

The expected behavior would be that only t is removed from the backend

jmcarp commented 10 years ago

remove is a classmethod of StoredObject, so the expected usage is something like Tag.remove(tag). But yes, remove is still available from instances, which is confusing. Not sure how to improve this--thoughts welcome.

chrisseto commented 10 years ago
def remove(cls):
    if isinstance(cls, StoredObject):
        # Remove just the instance here
    else:
        # Remove everything here

Could that potentially work?

jmcarp commented 10 years ago

Well, cls is always going to be passed as the schema class, never the instance. So I don't think so, unless I'm misunderstanding.

chrisseto commented 10 years ago

Right... sadly that doesnt work. My suggestion under the advice of BrianG would be to rename the cls.remove to cls.remove_all and then implement instance.remove as expected.