Skip to content

Commit 289e38b

Browse files
author
Dane Pilcher
committed
fix: set associatedWith to correct field with hasOne/hasMany and belongsTo
1 parent f0742a5 commit 289e38b

File tree

6 files changed

+1251
-101
lines changed

6 files changed

+1251
-101
lines changed

packages/appsync-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/__snapshots__/appsync-dart-visitor.test.ts.snap

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class Project extends Model {
630630
key: Project.TEAM,
631631
isRequired: false,
632632
ofModelName: (Team).toString(),
633-
associatedKey: Team.ID
633+
associatedKey: Team.PROJECT
634634
));
635635

636636
modelSchemaDefinition.addField(ModelFieldDefinition.field(
@@ -936,7 +936,7 @@ class Project2 extends Model {
936936
key: Project2.TEAM,
937937
isRequired: false,
938938
ofModelName: (Team2).toString(),
939-
associatedKey: Team2.ID
939+
associatedKey: Team2.PROJECT
940940
));
941941

942942
modelSchemaDefinition.addField(ModelFieldDefinition.field(
@@ -1536,7 +1536,7 @@ class Post extends Model {
15361536
key: Post.COMMENTS,
15371537
isRequired: false,
15381538
ofModelName: (Comment).toString(),
1539-
associatedKey: Comment.POSTCOMMENTSID
1539+
associatedKey: Comment.ID
15401540
));
15411541
});
15421542
}
@@ -1583,7 +1583,6 @@ class Comment extends Model {
15831583
static const classType = const _CommentModelType();
15841584
final String id;
15851585
final String? _content;
1586-
final String? _postCommentsId;
15871586

15881587
@override
15891588
getInstanceType() => classType;
@@ -1601,17 +1600,12 @@ class Comment extends Model {
16011600
}
16021601
}
16031602

1604-
String? get postCommentsId {
1605-
return _postCommentsId;
1606-
}
1603+
const Comment._internal({required this.id, required content}): _content = content;
16071604

1608-
const Comment._internal({required this.id, required content, postCommentsId}): _content = content, _postCommentsId = postCommentsId;
1609-
1610-
factory Comment({String? id, required String content, String? postCommentsId}) {
1605+
factory Comment({String? id, required String content}) {
16111606
return Comment._internal(
16121607
id: id == null ? UUID.getUUID() : id,
1613-
content: content,
1614-
postCommentsId: postCommentsId);
1608+
content: content);
16151609
}
16161610

16171611
bool equals(Object other) {
@@ -1623,8 +1617,7 @@ class Comment extends Model {
16231617
if (identical(other, this)) return true;
16241618
return other is Comment &&
16251619
id == other.id &&
1626-
_content == other._content &&
1627-
_postCommentsId == other._postCommentsId;
1620+
_content == other._content;
16281621
}
16291622

16301623
@override
@@ -1636,32 +1629,28 @@ class Comment extends Model {
16361629

16371630
buffer.write(\\"Comment {\\");
16381631
buffer.write(\\"id=\\" + \\"$id\\" + \\", \\");
1639-
buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\");
1640-
buffer.write(\\"postCommentsId=\\" + \\"$_postCommentsId\\");
1632+
buffer.write(\\"content=\\" + \\"$_content\\");
16411633
buffer.write(\\"}\\");
16421634

16431635
return buffer.toString();
16441636
}
16451637

1646-
Comment copyWith({String? id, String? content, String? postCommentsId}) {
1638+
Comment copyWith({String? id, String? content}) {
16471639
return Comment(
16481640
id: id ?? this.id,
1649-
content: content ?? this.content,
1650-
postCommentsId: postCommentsId ?? this.postCommentsId);
1641+
content: content ?? this.content);
16511642
}
16521643

16531644
Comment.fromJson(Map<String, dynamic> json)
16541645
: id = json['id'],
1655-
_content = json['content'],
1656-
_postCommentsId = json['postCommentsId'];
1646+
_content = json['content'];
16571647

16581648
Map<String, dynamic> toJson() => {
1659-
'id': id, 'content': _content, 'postCommentsId': _postCommentsId
1649+
'id': id, 'content': _content
16601650
};
16611651

16621652
static final QueryField ID = QueryField(fieldName: \\"comment.id\\");
16631653
static final QueryField CONTENT = QueryField(fieldName: \\"content\\");
1664-
static final QueryField POSTCOMMENTSID = QueryField(fieldName: \\"postCommentsId\\");
16651654
static var schema = Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) {
16661655
modelSchemaDefinition.name = \\"Comment\\";
16671656
modelSchemaDefinition.pluralName = \\"Comments\\";
@@ -1673,12 +1662,6 @@ class Comment extends Model {
16731662
isRequired: true,
16741663
ofType: ModelFieldType(ModelFieldTypeEnum.string)
16751664
));
1676-
1677-
modelSchemaDefinition.addField(ModelFieldDefinition.field(
1678-
key: Comment.POSTCOMMENTSID,
1679-
isRequired: false,
1680-
ofType: ModelFieldType(ModelFieldTypeEnum.string)
1681-
));
16821665
});
16831666
}
16841667

0 commit comments

Comments
 (0)