Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/src/bones_api_condition_sql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,21 @@ class ConditionSQLEncoder extends ConditionEncoder {
);
}

final keys = c.keys.cast<ConditionKeyField>();
final keys = c.keys;
if (keys.isEmpty) {
throw ConditionEncodingError('Empty key path: $c');
}

ConditionKeyField getKey(int index) {
var k = keys[index];
if (k is! ConditionKeyField) {
throw ConditionEncodingError(
"key[$index] is not a `ConditionKeyField`: $k",
);
}
return k;
}

FutureOr<MapEntry<Type, String>> walkKeys({
required int index,
required String sourceTable,
Expand All @@ -512,7 +522,7 @@ class ConditionSQLEncoder extends ConditionEncoder {
schemeProvider: schemeProvider,
context: context,
targetTable: sourceTable,
key: keys[index],
key: getKey(index),
);
}

Expand All @@ -527,7 +537,7 @@ class ConditionSQLEncoder extends ConditionEncoder {
c: c,
sourceScheme: scheme,
sourceTable: sourceTable,
key: keys[index],
key: getKey(index),
).resolveMapped(
(nextTable) => walkKeys(index: index + 1, sourceTable: nextTable),
);
Expand Down
8 changes: 6 additions & 2 deletions lib/src/bones_api_entity_db_sql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ extension on List<_JoinEntry> {
/// ordered correctly, or `false` if a best-effort fallback order was used.
bool sortJoins(Set<String> initialAliases) {
final List<_JoinEntry> joins = this;
// No ordering needed for zero or one JOIN.
if (joins.length <= 1) {
// No ordering needed for zero JOINs:
if (joins.isEmpty) {
return true;
}
// No ordering needed for a single JOIN; only check if it is resolved:
else if (joins.length == 1) {
var resolved = joins.first.refsResolved(initialAliases);
return resolved;
}
Expand Down
Loading