30 lines
892 B
Python
30 lines
892 B
Python
from sqlalchemy.orm import joinedload
|
|
from .models import User, Room, Inventory, WorkLog
|
|
|
|
def eager_load_user_relationships(query):
|
|
return query.options(
|
|
joinedload(User.supervisor),
|
|
joinedload(User.location).joinedload(Room.room_function)
|
|
)
|
|
|
|
def eager_load_inventory_relationships(query):
|
|
return query.options(
|
|
joinedload(Inventory.owner),
|
|
joinedload(Inventory.brand),
|
|
joinedload(Inventory.item),
|
|
joinedload(Inventory.location).joinedload(Room.room_function)
|
|
)
|
|
|
|
def eager_load_room_relationships(query):
|
|
return query.options(
|
|
joinedload(Room.area),
|
|
joinedload(Room.room_function),
|
|
joinedload(Room.inventory),
|
|
joinedload(Room.users)
|
|
)
|
|
|
|
def eager_load_worklog_relationships(query):
|
|
return query.options(
|
|
joinedload(WorkLog.contact),
|
|
joinedload(WorkLog.work_item)
|
|
)
|