notifications/statistics returns when no stats exist for today

moved filtering from WHERE to JOIN ON so that when join suceeds but filter fails, we dont lose the service's data from the results set
This commit is contained in:
Leo Hemsted
2016-05-26 16:46:16 +01:00
parent 83df16025d
commit a90a18541f
2 changed files with 37 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
from sqlalchemy import (desc, func, Integer, or_, asc)
from sqlalchemy import (desc, func, Integer, or_, and_, asc)
from sqlalchemy.sql.expression import cast
from datetime import (
@@ -62,11 +62,13 @@ def dao_get_potential_notification_statistics_for_day(day):
Service.id,
NotificationStatistics
).outerjoin(
Service.service_notification_stats
).filter(
or_(
NotificationStatistics.day == day,
NotificationStatistics.day == None # noqa
NotificationStatistics,
and_(
Service.id == NotificationStatistics.service_id,
or_(
NotificationStatistics.day == day,
NotificationStatistics.day == None # noqa
)
)
).order_by(
asc(Service.created_at)