Вызовите SQLAlchemy.paginate() в операторе выбора, чтобы получить объект разбиения на страницы.
Следующий вариант работает, но в конечном итоге я получаю ошибку, потому что paginate() для объединения( ) не возвращает объекты Item, а вместо этого возвращает только список целых чисел:
Код: Выделить всё
'int object' has no attribute 'id'
Код: Выделить всё
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
items_names = db.select(Item).filter(name=="eve")
items_property1 = db.select(Item).join(Item.properties1).filter(Property1.name=="eve")
items_property2 = db.select(Item).join(Item.properties2).filter(Property2.name=="eve")
results = db.paginate(db.union(items_names, items_property1, items_property2), per_page=50))
print(f"This is paginated page: {results.page}")
for item in results:
print(item.id)
print(item.name)
print("\n")
Код: Выделить всё
# Example Run output:
items_names = [Item, Item]
items_property1 = [Item, Item]
items_property2 = [Item]
results = [1,2,3,4] # > Error occurs in for loop since I just get integers in results[]
for item in results:
print(1.id) #
Подробнее здесь: [url]https://stackoverflow.com/questions/79127186/flask-sqlalchemy-combining-paginate-and-union-results-together-returns-only[/url]