validateIdAndPrimaryKeyConflict static method

String? validateIdAndPrimaryKeyConflict(
  1. ElementAnnotation? idAnnotation,
  2. ElementAnnotation? columnAnnotation
)

Validate that @Id and @PrimaryKey are not used together on the same field Returns error message if invalid, null if valid

Implementation

static String? validateIdAndPrimaryKeyConflict(
  ElementAnnotation? idAnnotation,
  ElementAnnotation? columnAnnotation,
) {
  if (idAnnotation == null || columnAnnotation == null) {
    return null;
  }

  // Check if Column has primaryKey: true
  try {
    final source = columnAnnotation.toSource();
    if (source.contains('primaryKey') &&
        source.contains('primaryKey: true')) {
      return 'Cannot use both @Id and @Column(primaryKey: true) on the same field. '
          'Use @Id for single-field primary keys or @Column(primaryKey: true) for composite keys with @PrimaryKey.';
    }
  } catch (e) {
    // Silently fail
  }

  return null;
}