* Which Category is your question related to? *
GraphQL, DynamoDB, gql-compile
* What AWS Services are you utilizing? *
AppSync, DynamoDB
Hello,
I have the following schema:
type Person
@model
{
id: ID!
firstname: String!
lastname: String!
member: Member
.....
}
type Membership
@model
{
id: ID!
name: String!
price: Float!
.....
}
type Member {
active: Boolean!
memberships: [Membership!] @connection
.....
}
The Member type is not a model. As there is always one and exactly one Member type per Person I prefer not to have a separate table for this.
Clearly @connections can only be used in @model types.
So my question would be: Is there a way to solve this? Or is the extra table the only way?
Thanks and regards,
Wilco
Yes since what you are looking to do here is a many-to-many connection.
Connection Docs
As @SwaySway mentioned above, there's a "Many-To-Many Connections" section in the docs listed above to solve your use-case.
@SwaySway
Thanks for your reply. I tried the many-to-many approach but don't get the result I expected/wanted.
I have the following:
type Person
@model
{
id: ID!
firstname: String!
lastname: String!
member: Member
.....
}
type Membership
@model
{
id: ID!
name: String!
price: Float!
persons: [Person!] (name: "MembershipPerson")
.....
}
type Member {
@model(queries: null)
active: Boolean!
memberships: [Membership!] @connection(name: "PersonMembership")
.....
}
type PersonToMembership {
@model(queries: null)
id: ID!
person: Person! @connection(name: "MembershipPerson")
memberships: Membership! @connection(name: "PersonMembership")
.....
}
It looks like I can only create the relation between Membership and Member. But I want the entire Person type when querying "Memberships". How would I solve this?
Regards,
Wilco
Why was this closed? @CoonHouse is correct in that this doesn't seem like a many-to-many connection use case. I'm having the same issue right now and it would be great to have the amplify team actually address this.
I have the same issue
I also have the same issue
Same issue. Why is an extra @model/table necessary for this use case?
Same issue.
@undefobj any comments on this one?
Same issue here. It would be great if this could be addressed.
Most helpful comment
Why was this closed? @CoonHouse is correct in that this doesn't seem like a many-to-many connection use case. I'm having the same issue right now and it would be great to have the amplify team actually address this.