#✅ - Huge Problem with Many-to-Many relations

5 messages · Page 1 of 1 (latest)

opaque brook
#

I am using amplify Gen2
Backend is running on these versions:

"@aws-amplify/backend": "^0.13.0-beta.11",
"@aws-amplify/backend-cli": "^0.12.0-beta.13",

I'm having a huge issue when working with many-to-many relationship on my generated Schema:
TLDR: the generated typings are wrong.

I encountered this issue in 2 places:

The generated types for the join tables do not contain an "id" property, which is an issue when i try to delete entries from that table. Trying to use aa selectionSet of ["id"] shows errors, but will work when forced (through //@ts-ignore or //@ts-expect-error)

The properties to access the related data are misnamed.
The type checker expects me to use the relationname in all lowercase letters:
"assignments.influencerassignment.id"
This will throw runtime errors, as this field does not exist on the database

Again, using ts comments, I can work around it by using the correct name, even though the TS type checkers flag this as an error
"assignments.influencerAssignment.id"
This lets me pull the correct data.

Either of these forced workaround makes it very annoying to work with the queried data, since they are all typed as any, requiring lots of unnecessary work to make sure they are correctly converted to my desired types

Am I doing anything wrong here, or is this a bug in the backend libraries?

Here's the relevant parts of my Schema (cut to fit the character limit)

    InfluencerAssignment: a
        .model({

            timelineEvents: a.manyToMany("TimelineEvent", { relationName: "EventAssignments" }),

        })
TimelineEvent: a
        .model({
            assignments: a.manyToMany("InfluencerAssignment", { relationName: "EventAssignments" }),

        })```
exotic citrus
opaque brook
exotic citrus
#

Thank you!

obtuse oasisBOT
#

✅ - Huge Problem with Many-to-Many relations