Skip to content

Commit 230cbcf

Browse files
committed
Warn when no definition is found for a specified primary key
1 parent 9967c32 commit 230cbcf

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

floor_generator/lib/processor/entity_processor.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ class EntityProcessor extends QueryableProcessor<Entity> {
221221
.getAnnotation(annotations.Entity)
222222
?.getField(AnnotationField.entityPrimaryKeys)
223223
?.toListValue()
224-
?.map((object) => object.toStringValue());
224+
?.map((object) => object.toStringValue())
225+
.toSet();
225226

226227
if (compoundPrimaryKeyColumnNames == null ||
227228
compoundPrimaryKeyColumnNames.isEmpty) {
@@ -237,6 +238,11 @@ class EntityProcessor extends QueryableProcessor<Entity> {
237238
throw _processorError.missingPrimaryKey;
238239
}
239240

241+
if (compoundPrimaryKeyFields.length !=
242+
compoundPrimaryKeyColumnNames.length) {
243+
throw _processorError.primaryKeyNotFound;
244+
}
245+
240246
return PrimaryKey(compoundPrimaryKeyFields, false);
241247
}
242248

floor_generator/lib/processor/error/entity_processor_error.dart

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ class EntityProcessorError {
1818
);
1919
}
2020

21+
InvalidGenerationSourceError get primaryKeyNotFound {
22+
return InvalidGenerationSourceError(
23+
'Primary key not found for ${_classElement.displayName}.',
24+
todo: 'Make sure that all the primary keys you defined exist as columns.',
25+
element: _classElement,
26+
);
27+
}
28+
2129
InvalidGenerationSourceError get missingParentColumns {
2230
return InvalidGenerationSourceError(
2331
'No parent columns defined for foreign key.',

0 commit comments

Comments
 (0)