- changed status to invalid
Materialized path relationship: `lazy="subquery"` not working while `subqueryload()` works
Issue #3056
invalid
The configuration:
class Node(Base):
__tablename__ = "node"
id = Column(Integer, primary_key=True)
path = Column(String(500), nullable=False)
children = relationship(
"Node", primaryjoin=remote(foreign(path)).like(path.concat(".%")),
viewonly=True, lazy="subquery")
The query:
db.add(Node(path="foo"))
db.add(Node(path="foo.bar"))
db.add(Node(path="foo.bar.baz"))
db.flush()
db.query(Node).all() # issues one SELECT to find all nodes
db.query(Node).options(subqueryload(Node.children)).all() # issues two SELECTs to find all nodes and their children
The lazy="subquery"
declaration does not seem to have any effect.
Comments (1)
-
repo owner - Log in to comment
this is because self-referential relationships don't structurally eager load unless you give it a "join depth": http://docs.sqlalchemy.org/en/rel_0_9/orm/relationships.html#configuring-self-referential-eager-loading.
feel free to reopen if that doesn't resolve.