Created
March 24, 2020 20:38
-
-
Save b4oshany/fec076a49d083caa7efb8ef3b8ac9608 to your computer and use it in GitHub Desktop.
Kotti self join
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kotti.resources import Content | |
from sqlalchemy.orm import aliased | |
parent_table = aliased(Content) | |
# Perform a self join with a where query, which adds the | |
# following line:: | |
# left join contents as n on contents.id = n.id | |
# where n.title like '%<title>%' | |
query = query.outerjoin( | |
parent_table, parent_table.id == Content.id | |
).filter(parent_table.title.ilike( | |
"%{}%".format(parent_title))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment