I'm trying to do something like this:
Session.query(some_table).filter("/some/path/to/element".startswith(some_table.path)).all()
That is, get all "parent" elements of a certain path. I tried doing it like this:
Session.query(some_table).filter(sqlalchemy.sql.expression.literal("/some/path/to/element").startswith(some_table.pat开发者_StackOverflow中文版h)).all()
But I get some weird exceptions with it. I wonder if what I want is actually even possible.
i don't understand what you are try to do, because it not that filter just get a boolean filter should get an expression that will loop over it to filter data.
look at this example (i don't think you want this one but maybe it can give you some Hint):
Session.query(some_table).filter(some_table.path.like('%/some/path/to/element'))
or this example because if i understand well you want to get all parent path of a given path:
import os
a = '/some/path/to/element'
parent_path = []
# Get all parent path
while a != '/':
a = os.path.split(a)[0]
parent_path.append(a)
Session.query(some_table).filter(some_table.path.in_(parent_path))
Hope this will help
Actually the second example that I gave works, I just made a silly mistake in the column name. I'm sorry for wasting your time.
精彩评论