belongsTo static method
ModelFieldDefinition
belongsTo({
- required QueryField key,
- bool isRequired = true,
- required String ofModelName,
- QueryField? associatedKey,
- @Deprecated('Please use the latest version of Amplify CLI to regenerate models') String? targetName,
- List<
String> ? targetNames,
Implementation
static ModelFieldDefinition belongsTo(
{required QueryField key,
bool isRequired = true,
required String ofModelName,
QueryField? 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,
targetName: targetName,
targetNames: targetNames,
associatedName: associatedName,
associatedType: associatedType));
}