Eager Fetch Type On Association (ARCH2060)
هذا المحتوى غير متوفر بلغتك بعد.
Key python.orm.eager-fetch-type-on-association · Severity warning · Category orm
Declaring a relation as always-eager at the mapping level over-fetches on every query of the owning entity. Decide eager loading per query instead.
Incorrect
Section titled “Incorrect”class Author(Base): books = relationship("Book", lazy="joined") # fetches books on every Author queryCorrect
Section titled “Correct”class Author(Base): books = relationship("Book", lazy="select") # only when needed
session.query(Author).options(joinedload(Author.books)) # opt in per queryLeave the relation lazy by default; opt into eager loading on the specific query that needs it, not in the mapping.