Fix error: Query.join() got an unexpected keyword argument 'aliased'
This commit is contained in:
parent
a845ade3df
commit
591ffa6055
1 changed files with 16 additions and 13 deletions
29
app.py
29
app.py
|
|
@ -960,30 +960,33 @@ def browse_facets() -> Response:
|
||||||
return jsonify(params=params, facets=facets, prop_labels=find_more_props)
|
return jsonify(params=params, facets=facets, prop_labels=find_more_props)
|
||||||
|
|
||||||
|
|
||||||
def get_db_items(params):
|
def get_db_items(params: list[tuple[str, str]]):
|
||||||
"""Get items for browse page based on criteria."""
|
"""Get items for browse page based on criteria."""
|
||||||
q = Item.query.filter_by(is_artwork=True) # type: ignore
|
q = Item.query.filter_by(is_artwork=True) # type: ignore
|
||||||
|
|
||||||
for pid, qid in params:
|
for pid, qid in params:
|
||||||
q = q.join(Triple, Item.item_id == Triple.subject_id, aliased=True).filter(
|
t = aliased(Triple)
|
||||||
Triple.predicate_id == pid[1:], Triple.object_id == qid[1:]
|
q = q.join(t, Item.item_id == t.subject_id).filter(
|
||||||
|
t.predicate_id == int(pid[1:]),
|
||||||
|
t.object_id == int(qid[1:]),
|
||||||
)
|
)
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
|
||||||
|
def get_db_facets(params: list[tuple[str, str]]):
|
||||||
def get_db_facets(params):
|
|
||||||
t = aliased(Triple)
|
t = aliased(Triple)
|
||||||
q = database.session.query(t.predicate_id, func.count().label("count"), t.object_id)
|
q = database.session.query(
|
||||||
|
t.predicate_id, func.count().label("count"), t.object_id
|
||||||
|
)
|
||||||
facet_limit = 18
|
facet_limit = 18
|
||||||
|
|
||||||
for pid, qid in params:
|
for pid, qid in params:
|
||||||
q = q.join( # type: ignore
|
t2 = aliased(Triple)
|
||||||
Triple, t.subject_id == Triple.subject_id, aliased=True
|
q = q.join(t2, t.subject_id == t2.subject_id).filter(
|
||||||
).filter(
|
t2.predicate_id == int(pid[1:]),
|
||||||
Triple.predicate_id == pid[1:],
|
t2.object_id == int(qid[1:]),
|
||||||
Triple.object_id == qid[1:],
|
t.predicate_id != int(pid[1:]),
|
||||||
t.predicate_id != pid[1:],
|
t.object_id != int(qid[1:]),
|
||||||
t.object_id != qid[1:],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
q = q.group_by(t.predicate_id, t.object_id)
|
q = q.group_by(t.predicate_id, t.object_id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue