Conditional query: Issues with boxing and deleting

Thanks to @weiznich on the Gitter, I managed to make it work with the following:

[...]

use db::SqlId;

        let raw_id: SqlId<Event> = item_id.into();
        use db::schema::events::dsl::events;
        let sql_previous = events.find(raw_id.clone()).first::<SqlEvent>(&*self.0)?;

        let associated_occurrences = SqlOccurrence::belonging_to(&sql_previous);
        let previous_occurrences: Vec<OccurrenceWithLocation> = associated_occurrences
            .filter(apply_occurrence_filter(&filter))
            .load::<SqlOccurrence>(&*self.0)?
            .into_iter()
            .map(|sql_occurrence| {
                let (_, occurrence) = sql_occurrence.into();

                occurrence
            })
            .collect();

        diesel::delete(associated_occurrences.filter(apply_occurrence_filter(&filter)))
            .execute(&*self.0)?;

[...]

fn apply_occurrence_filter(
    filter: &OccurrenceFilter,
) -> Box<
    dyn BoxableExpression<
        db::schema::occurrences::table,
        diesel::sqlite::Sqlite,
        SqlType = diesel::sql_types::Bool,
    >,
> {
    use db::schema::occurrences::dsl::*;
    let mut query: Box<
        dyn BoxableExpression<
            db::schema::occurrences::table,
            diesel::sqlite::Sqlite,
            SqlType = diesel::sql_types::Bool,
        >,
    > = Box::new(true.into_sql::<diesel::sql_types::Bool>());
    if let Some(before) = filter.before {
        query = Box::new(query.and(start.lt(before)))
    }
    if let Some(after) = filter.after {
        query = Box::new(query.and(start.gt(after)))
    }

    query
}