You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Existing Problem
Fluent queries do not permit conditional filtering by properties shared among joined ModelAlias(es). Currently, you can only create a filter such as this on the originally queried model. For example, this is currently possible:
finalclassHomeTeam:ModelAlias{staticletname="home_teams"letmodel=Team()}finalclassAwayTeam:ModelAlias{staticletname="away_teams"letmodel=Team()}/// Find games that were popular enough for the crowd to be larger/// than the number of players playing it. Match.query(on:self.database).join(HomeTeam.self, on: \Match.$homeTeam.$id == \HomeTeam.$id).join(AwayTeam.self, on: \Match.$awayTeam.$id == \AwayTeam.$id)/// You can currently conditionally filter the originally /// queried Model type if types match (in this case, /// crowd size and total players would be of type Int).filter(\Match.$crowd,.greaterThan, \Match.$totalPlayers).all()
Proposed Solution
Query builders would allow conditional filtering of joined ModelAliases. The call site would look something like:
Match.query(on:self.database).join(HomeTeam.self, on: \Match.$homeTeam.$id == \HomeTeam.$id).join(AwayTeam.self, on: \Match.$awayTeam.$id == \AwayTeam.$id)/// Here you can filter a ModelAlias according to properties shared with /// another ModelAlias of the same original Model type..filter(\HomeTeam.$score,.greaterThan, \AwayTeam.$score).all()
To achieve this, I imagine a modification of QueryBuilder+Filter.swift whereby existing filter methods are combined something similar to below to allow conditional filtering on Joined types:
/// Please note this code is for demonstration only /// and is not functional.@discardableResultpublicfunc filter<Left,Right>(
_ lhsField:KeyPath<FirstModelAlias,Left>,
_ method:DatabaseQuery.Filter.Method,
_ rhsField:KeyPath<SecondModelAlias,Right>)->Selfwhere Left:QueryableProperty,
Left.Model ==FirstModelAlias,
Right:QueryableProperty,
Right.Model ==SecondModelAlias{self.filter(FirstModelAlias.path(for: lhsField), method,SecondModelAlias.path(for: rhsField))}
The text was updated successfully, but these errors were encountered:
Existing Problem
Fluent queries do not permit conditional filtering by properties shared among joined ModelAlias(es). Currently, you can only create a filter such as this on the originally queried model. For example, this is currently possible:
Proposed Solution
Query builders would allow conditional filtering of joined ModelAliases. The call site would look something like:
To achieve this, I imagine a modification of
QueryBuilder+Filter.swift
whereby existing filter methods are combined something similar to below to allow conditional filtering on Joined types:The text was updated successfully, but these errors were encountered: