Skip to content

Commit

Permalink
fix(api): join events only when date_from/to are set
Browse files Browse the repository at this point in the history
  • Loading branch information
berdal84 committed Apr 24, 2024
1 parent 319d978 commit 285a86e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions api/src/crud/jobCrud.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ def get_page(session: Session,

# 2) Handle filters related to the events
# contains_eager is required to ensure events are loaded
query = session.query(models.Job).join(models.Job.events).options(contains_eager(models.Job.events))

if date_from != None and date_to != None:
query = query.filter( models.Event.date.between(date_from, date_to) )
elif date_from != None:
query = query.filter( models.Event.date >= date_from )
elif date_to != None:
query = query.filter( models.Event.date <= date_to )
if date_from != None or date_to != None:

query = query.join(models.Event).options(contains_eager(models.Job.events))

if date_from != None :
query = query.filter( models.Event.date >= date_from )

if date_to != None:
query = query.filter( models.Event.date <= date_to )

# 3) Handle pagination
query = query.offset(skip).limit(limit)
Expand Down

0 comments on commit 285a86e

Please sign in to comment.