Hello everyone.
I was wondering what is the best way to perform a query filtering by
"not" in a python-way.
In python:
>> not(None)
True
>> not(list())
True
Let's say I have a class that has the typical "children" relationship:
class Foo(declarative_base):
__tablename__ = "foos"
_name = Column("name", String(50))
_parentId = Column("parent_id", Integer, ForeignKey("foos.id"),
key="parentId")
_children = relationship("Foo",
collection_class=set,
backref=backref("_parent", remote_side=lambda: Foo.id,
uselist=False),
)
def __init__(self):
self.name = ""
self.parentId = None
self.parent = None
self.children = set()
And I want to query the class where children "is not" (meaning is None
or is an empty set).
I can easily query with the filter (Foo.children == None) but what
about the empty set? And a comparator suitable for both? (empty sety
and None) I'm sure there's a way, but googling "not sqlalchemy
comparison" doesn't help much
If I try the sqlalchemy.not_, I get an SQL programming error (which
doesn't surprise me, because it generates an empty comparison)
Thank you
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.