i dont think with_loader_criteria ever expected the target entity to be part of
"secondary" in a relationship(). I have no idea what that would do and I'm
surprised it works at all.
I would try instead to map from A->A_rel_B->B explicitly and use two
relationships for this join.
On Fri, Jan 7, 2022, at 12:51 PM, Tomas Pavlovsky wrote:
> Hello Mike,
>
>
> class X()
> id: id: int = Column( Integer, primary_key=True)
> a_id:int = Column(Integer, ForeignKey("A.id"))
>
> subq = select(A_rel_B).join(B).order(B.size).limit(10)
>
> class A()
> id: id: int = Column( Integer, primary_key=True)
> bs = relationship(B, viewonly=True, secondary=subq,
> uselist=False,primaryjoin=and_(A.id == subq.c.a_id))
>
> class B()
> id: id: int = Column( Integer, primary_key=True)
> size= Column( Integer)
>
> class A_rel_B()
> a_id: :int = Column(Integer, ForeignKey("A.id"))
> b_id: :int = Column(Integer, ForeignKey("B.id"))
>
> x: int
> q = select(X).options(
> selectinload(A).options(joinedload(A.bs)),
> with_loader_criteria(A_rel_B, func.fn(A_rel_B.b_id, x).is_(True))
> )
>
> When i add with_loader_criteria(A_rel_B, func.fn(A_rel_B.b_id, x).is_(True)),
> then x value is cached and don't change. It is ok?
>
> Thanks
>
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/0fb2b5d7-4321-4349-add7-7256cba8aea2n%40googlegroups.com
>
> <https://groups.google.com/d/msgid/sqlalchemy/0fb2b5d7-4321-4349-add7-7256cba8aea2n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/247cbd1e-9e4a-4554-bda3-dcfe61f2d486%40www.fastmail.com.