belongsTo static method
ModelFieldDefinition
belongsTo({
- required QueryField<
Object?> key, - bool isRequired = true,
- required String ofModelName,
- QueryField<
Object?> ? associatedKey, - @Deprecated('Please use the latest version of Amplify CLI to regenerate models') String? targetName,
- List<
String> ? targetNames,
Implementation
static ModelFieldDefinition belongsTo({
required QueryField<Object?> key,
bool isRequired = true,
required String ofModelName,
QueryField<Object?>? associatedKey,
@Deprecated(
'Please use the latest version of Amplify CLI to regenerate models',
)
String? targetName,
List<String>? targetNames,
}) {
// Extra code needed due to lack of nullability support
String? associatedName;
String? associatedType;
associatedName = associatedKey?.fieldName;
associatedType = associatedKey?.fieldType?.ofModelName ?? ofModelName;
return field(
key: key,
isRequired: isRequired,
ofType:
ModelFieldType(ModelFieldTypeEnum.model, ofModelName: ofModelName),
association: ModelAssociation(
associationType: ModelAssociationEnum.BelongsTo,
// Allow support for old schemas
// ignore: deprecated_member_use_from_same_package
targetName: targetName,
targetNames: targetNames,
associatedName: associatedName,
associatedType: associatedType,
),
);
}