Steve Zatz wrote:
I realize this is actually an SQL question but I haven't been able to
figure out the answer.
In a simple self-referential table, the following produces all the
Nodes that are parents to some child node(s):
node_table_alias = node_table.alias()
parents = session.query(Node).filter(Node.id == node_table_alias.c.parent_id)
I can't figure out the analogous query that produces all the Nodes
that are not parents to another node. It is clear that:
non_parents = session.query(Node).filter(Node.id !=
node_table_alias.c.parent_id)
doesn't work but I can't figure out what the right query is. Any help
would be appreciated.
another option is:
.query(Node).filter(not_(Node.id.in_(select([Node.parent_id]))))