Skip to content

Amplify Gen 2 model creation problem #6077

@ozguraltunsogut

Description

@ozguraltunsogut

Hello,
I prepared two simple models below,
const schema = a.schema({
Users: a
.model({
id: a.id().required(),
name: a.string(),
eMail: a.string(),
gsm: a.string(),
nickName: a.string(),
motto: a.string(),
introduction: a.string(),
messagesReceived: a.hasMany("Messages", "user1Id"),
messagesSent: a.hasMany("Messages", "user2Id")

  }
).authorization((allow) => allow.authenticated("userPools")),
Messages: a
.model({
  user1Id: a.id().required(),
  user1: a.belongsTo("Users", "user1Id"),
  messageDate: a.datetime().required(),
  messageBody: a.string().required(),
  user2Id: a.id().required(),
  user2: a.belongsTo("Users", "user2Id"),
  messageType: a.string().required(),
  isRead: a.boolean().default(false),
  readDate: a.datetime()
})
.identifier(["user1Id", "messageDate"])
.authorization((allow) => allow.authenticated("userPools"))

});

When I run the command "npx ampx generate graphql-client-code --format modelgen --model-target dart --out ./lib/models" to generate GraphQL client codes, code gen doesn't create a property userId2 for Messages model as below.
/** This is an auto generated class representing the Messages type in your schema. */
class Messages extends amplify_core.Model {
static const classType = const _MessagesModelType();
final String? _user1Id;
final Users? _user1;
final amplify_core.TemporalDateTime? _messageDate;
final String? _messageBody;
final Users? _user2;
final String? _messageType;
final bool? _isRead;
final amplify_core.TemporalDateTime? _readDate;
final amplify_core.TemporalDateTime? _createdAt;
final amplify_core.TemporalDateTime? _updatedAt;

I have defined hasMany and belongsTo properties for both user1Id and user2Id. user1Id created but user2Id not.
Is there anyone has any idea about this problem?

Best regards.

Metadata

Metadata

Assignees

Labels

GraphQL APIIssues related to the API (GraphQL) CategoryquestionA question about the Amplify Flutter libraries

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions