Skip to content

Commit

Permalink
Warn when no definition is found for a specified primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
Huluk committed Oct 30, 2023
1 parent 9967c32 commit 230cbcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion floor_generator/lib/processor/entity_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ class EntityProcessor extends QueryableProcessor<Entity> {
.getAnnotation(annotations.Entity)
?.getField(AnnotationField.entityPrimaryKeys)
?.toListValue()
?.map((object) => object.toStringValue());
?.map((object) => object.toStringValue())
.toSet();

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

if (compoundPrimaryKeyFields.length !=
compoundPrimaryKeyColumnNames.length) {
throw _processorError.primaryKeyNotFound;
}

return PrimaryKey(compoundPrimaryKeyFields, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class EntityProcessorError {
);
}

InvalidGenerationSourceError get primaryKeyNotFound {
return InvalidGenerationSourceError(
'Primary key not found for ${_classElement.displayName}.',
todo: 'Make sure that all the primary keys you defined exist as columns.',
element: _classElement,
);
}

InvalidGenerationSourceError get missingParentColumns {
return InvalidGenerationSourceError(
'No parent columns defined for foreign key.',
Expand Down

0 comments on commit 230cbcf

Please sign in to comment.