Sqlalchemy Include Empty Relationship With Join And Contains_eager
I have 2 models Recording and Recording_results like so class Recording(Base): __tablename__ = 'recordings' id = Column(Integer, primary_key=True) filename = Column(St
Solution 1:
An INNER JOIN
like the one produced by
join(Recording.recording_results)
will only produce a row when a matching row exists on both sides of the join.
A LEFT [OUTER] JOIN
, produced by Query.outerjoin()
will include rows on the left that have no matching row on the right, so changing the join type helps, if you have no additional predicates that use the right table.
In fact you do, but it sort of "works" as is, because it is an IS NULL
check. Still, its proper place is the ON
clause in this case:
outerjoin(RecordingResult, and_(Recording.recording_results, RecordingResult.deletedd_at == None))
which replaces the use of filter()
.
Post a Comment for "Sqlalchemy Include Empty Relationship With Join And Contains_eager"