init method
void
init()
Implementation
void init() {
objectType = objectType ?? ObjectType.table;
print('init() -> ${modelName == null ? '' : 'modelname: $modelName,'}tableName:$tableName');
modelName = toModelName(modelName, tableName!);
if (relationType != RelationType.MANY_TO_MANY) {
primaryKeyType = primaryKeyType ?? PrimaryKeyType.integer_auto_incremental;
}
useSoftDeleting = useSoftDeleting ?? false;
initialized = false;
if (primaryKeyName != null && primaryKeyName!.isNotEmpty) {
if (!primaryKeyNames.contains(primaryKeyName)) {
primaryKeyNames.add(primaryKeyName!);
primaryKeyTypes.add(primaryKeyType == PrimaryKeyType.text ? 'String' : 'int');
}
}
final List<SqfEntityFieldType> _addRelatedFields = <SqfEntityFieldType>[];
for (final field in fields!) {
field
..table = field.table ?? this
..isNotNull = field.isNotNull ?? false;
if (field is SqfEntityFieldRelationshipBase) {
field
..relationshipName = field.relationshipName ?? modelName
..formDropDownTextField = field.formDropDownTextField ?? getformListTitleField(field.table!)
..dbType = field.table == null
? primaryKeyType != PrimaryKeyType.text
? DbType.integer
: DbType.text
: field.table!.primaryKeyType != PrimaryKeyType.text
? DbType.integer
: DbType.text
..deleteRule = field.deleteRule ?? DeleteRule.NO_ACTION
..relationType = field.relationType ?? RelationType.ONE_TO_MANY;
if (field.relationType != RelationType.MANY_TO_MANY) {
relationType = relationType ?? field.relationType;
}
if (field.relationType == RelationType.ONE_TO_ONE && field.table != this) {
// primaryKeyName = primaryKeyName != null && primaryKeyName.isNotEmpty
// ? '_$primaryKeyName'
// : '';
if ((primaryKeyName == null || primaryKeyName!.isEmpty) && field.isPrimaryKeyField!) {
primaryKeyType = field.table!.primaryKeyType;
}
field.fieldName = field.fieldName == null || field.fieldName!.startsWith('_') ? field.fieldName : '_${field.fieldName}';
}
field.primaryKeyIndex = 0;
if (!field.relationshipFields.contains(field)) {
field.relationshipFields.add(field);
}
int _primaryKeyIndex = 0;
field.table!.fields!.where((f) => f.isPrimaryKeyField == true && f.fieldName != field.fieldName!).forEach((f) {
_primaryKeyIndex++;
final newField = SqfEntityFieldBase(
//'${tocamelCase(field.table!.tableName!)}${toCamelCase(f.fieldName!)}',
(tableName == field.table!.tableName ? f.fieldName : '${tocamelCase(field.table!.tableName!)}${toCamelCase(f.fieldName!)}')!,
f.dbType!,
defaultValue: f.defaultValue,
primaryKeyIndex: _primaryKeyIndex,
minValue: f.minValue,
maxValue: f.maxValue);
//print('before field.relationshipFields.add. newField=${newField.fieldName} field.relationshipFields=${field.relationshipFields.map((e) => e.fieldName!).join(',')} ');
field.relationshipFields.add(newField);
if (fields!.where((fi) => fi.fieldName == newField.fieldName).isEmpty) {
_addRelatedFields.add(newField);
}
});
}
if (field.isPrimaryKeyField != null && field.isPrimaryKeyField!) {
if (!primaryKeyNames.contains(field.fieldName!)) {
primaryKeyNames.add(field.fieldName!);
primaryKeyTypes.add(dartType[field.dbType!.index].toString());
}
}
if (field.dbType == DbType.date || field.dbType == DbType.datetime || field.dbType == DbType.datetimeUtc) {
field.minValue = field.minValue ?? '1900-01-01';
}
}
for (final newField in _addRelatedFields) {
fields!.add(newField);
}
//print( '>>>>>>>>>>>>>>>>>>>>>>>>>>>> SqfEntityTableBase of [$tableName](${primaryKeyNames.join(',')}) init() successfully');
}