async mode and relationship more than one level deep

91 views
Skip to first unread message

sector119

unread,
Jul 21, 2021, 4:25:05 PM7/21/21
to sqlalchemy
Hello, Mike

When I want to use some relationship I just set selectinload option on it like

s = select(Database).options(selectinload(Database.person))

Here Database.person is relationship with Person model

But what to do if I want to access some relationship of Person model? For example Person.city,

I got errors when I set selectinload(Database.person.city) or selectinload(Person.city)

Thank You

sector119

unread,
Jul 21, 2021, 4:57:27 PM7/21/21
to sqlalchemy
s = select(
  Database
).options(
  selectinload(
    Database.person
  ).options(
    joinedload(Person.city)
  )
)

среда, 21 июля 2021 г. в 23:25:05 UTC+3, sector119:

Mike Bayer

unread,
Jul 21, 2021, 5:26:57 PM7/21/21
to noreply-spamdigest via sqlalchemy
you need to chain those like:

selectinload(Database.person).selectinload(Person.city)

docs:

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
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 sqlalchemy+...@googlegroups.com.

sector119

unread,
Jul 22, 2021, 6:47:59 AM7/22/21
to sqlalchemy
Thank You, works like a charm

четверг, 22 июля 2021 г. в 00:26:57 UTC+3, Mike Bayer:
Reply all
Reply to author
Forward
0 new messages