Do you need it to be an actual relationship? It's common to use an
association proxy for this:
https://docs.sqlalchemy.org/en/13/orm/extensions/associationproxy.html#simplifying-association-objects
Hope that helps,
Simon
On Fri, Mar 20, 2020 at 7:47 PM Mark Aquino wrote:
>
> I'd like to create a relationship that joins a table linked to a related
> table on a model:
>
> I have a Vessel class, a Well class, and a Batch class.
>
> Vessel and Well are related via a FK on Well (well.vessel_id) but Batch is a
> many to many relationship with Well, e.g.
>
> Batch(Base):
> id = Column(Integer)
>
> Well(Base):
>id = Column(Integer)
>vessel_id = Column(Integer)
>batches = relationship("Batch", secondary="mix_well_tracked_entity")
>
> Is it possible to make a relationship on Vessel to the Batches linked to its
> wells?
>
> Vessel(Base):
>id = Column(Integer)
>wells = relationship("Well")
>wells_batches = relationship("Batch", ...???)
>
>
> select * from vessel v join well w on w.vessel_id = v.id join
> mix_well_tracked_entity mix1 on mix1.well_id = w.id join batch b on b.id =
> mix1.tracked_entity_id;
>
> --
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/54af97fe-9de7-4cb2-a4d9-96b33107c6af%40googlegroups.com.
--
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexc3eUFLWT0sPoqm%2B8RUM0eUKPhHq8kDiwFDPq6zBfn1Gw%40mail.gmail.com.