Closed kenchoong closed 3 years ago
In the previous comment, I state that in Amplify sandbox is able to create the Many to Many relationship for Order
and Product
. I test it locally, everything is working, I can create query the relationship in my project by this:
// given a orderId, get all the product in the order
export const queryProductWithOrderId = async (orderId) => {
let products = (await DataStore.query(OrderProduct))
.filter(pt => pt.order.id === orderId)
.map(pt => pt.product)
return products
}
This is appear in IndexedDB in console.
I need to TAKE THIS BACK, because when I deploy the sandbox in my aws account:
NO ANY DATA MODEL IS DEPLOY, which means that
- No data model appear in Admin UI
- No table deploy in DynamoDB
- When pull the environment using this amplify pull --appId the-app-id --envName staging after the sandbox is deploy
- No schema.graphql appear in my local project
Then I delete the whole amplify app. And create a new sandbox AGAIN, this is what I got:
You see? Totally same situation like what I describe in pervious comment.
Order
and Product
So totally same between Sandbox and Amplify UI. Many to many relationship cannot be created.
Followed all this tutorial:
I mean WOW. I totally not expect this which is so painful. Fed up, need to do something else for this moment, for those that can make this work, like whom in the tutorial above, I really dont know why yours can work, and mine just not working.
The sandbox : https://sandbox.amplifyapp.com/schema-design/8f03c299-2b46-4b6f-9cc0-c45f3cdf5a18
In summary:
Sandbox and Admin UI is the same, Many-to-Many relationship is totally NO WORKING. You unable to create, query the relationship between 2 model.
You can create it in Admin UI, Sandbox, and even in local by editing schema.graphql
and amplify push
like describe in this issue
I have the same issue happening in my project. It seems to have started this week that I am unable to create many to many relationships in the data modeler.
@martinrojas since this happen to you too, how you create many and many relationship now??
@kenchoong I haven't been able to create any. I have been working on other parts of the application hoping this gets fixed.
@martinrojas tough.. since cant do many-to-many, this is pretty useless now, to be honest
We're currently investigating this. Thanks for posting the issue.
@kenchoong one of the amplify staff on discord says that engineering is looking into it.
@kenchoong @martinrojas as a quick fix, can you try re-ordering your enums. You can do that by selecting them and move them to the last position in your schema and try again. E.g. Drag your enum card so it's the last card in the schema designer.
@letsbelopez errmm...tried what you suggest, but still the same
@letsbelopez
In my case I don't have enums in that model . this is the relationship that appears when I try to create the many to many
@kenchoong Re-order the enum card (The white square). Not the field.
@martinrojas it's easier for us to debug when we can see the whole schema. Could you re-create it in Sandbox and post a link, or there's a raw schema printed to the console after every update. You could post the raw schema too.
Post the version of the schema that's working before you try to make the relationship update.
Also if you have a custom type, move that card to the end, and try again
@letsbelopez surprisingly, this works when pull the enum to the last card in the schema
Lolz..
But this take me 10 days to figure this out. HAHAHAHAHAHAHAHA .. Like Really?
Thank you by the way..haha
@letsbelopez here is a screenshot of the amplify. I have moved all enums to the last cards. `type Team @model @auth(rules: [{allow: private, operations: [read, update]}]) { id: ID! Athletes: [Athlete] @connection(keyName: "byTeam", fields: ["id"]) name: String Groups: [Group] @connection(keyName: "byTeam", fields: ["id"]) }
type AthleteSurvey @model @auth(rules: [{allow: private}]) { id: ID! Athlete: Athlete @connection startTime: AWSDateTime qurrentQuestionId: String surveyQuestions: [SurveyQuestion] status: SurveyStatus }
type Question @model @auth(rules: [{allow: private}]) { id: ID! active: Boolean question: String questionsets: [QuestionSetQuestion] @connection(keyName: "byQuestion", fields: ["id"]) }
type SurveyResponseModel { expectedValue: String nextQuestion: String }
enum DayOfWeek { MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY }
type GroupQuestion { questionId: String! prompt: String! rePrompt: String responseModels: [SurveyResponseModel!]! }
type Group @model @key(name: "byTeam", fields: ["teamID"]) @auth(rules: [{allow: private}]) { id: ID! name: String GroupQuestionSets: [GroupQuestionSet] @connection(keyName: "byGroup", fields: ["id"]) teamID: ID }
type GroupQuestionSet @model @key(name: "byGroup", fields: ["groupID"]) @auth(rules: [{allow: private}]) { id: ID! groupID: ID groupQuestions: [GroupQuestion!]! name: String scheduleFrequency: ScheduleFrequency timeOfDay: AWSTime dayOfWeek: DayOfWeek dayOfMonth: Int lastBroadcast: AWSDateTime nextBroadcast: AWSDateTime }
enum SurveyStatus { CURRENT CANCELLED COMPLETE }
type QuestionSet @model @auth(rules: [{allow: private}]) { id: ID! name: String active: Boolean Questions: [QuestionSetQuestion] @connection(keyName: "byQuestionSet", fields: ["id"]) }
type SurveyQuestion { ID: String prompt: String rePrompt: String responseModels: [SurveyResponseModel] acceptedResponse: String acceptedResponseTime: AWSDateTime }
enum ScheduleFrequency { DAILY WEEKLY MONTHLY EVENT }
type Athlete @model @key(name: "byTeam", fields: ["teamID"]) @auth(rules: [{allow: private}]) { id: ID! firstName: String lastName: String email: AWSEmail teamID: ID phoneNumber: AWSPhone playerNumber: Int playerPosition: String }
type QuestionSetQuestion @model(queries: null) @key(name: "byQuestionSet", fields: ["questionsetID", "questionID"]) @key(name: "byQuestion", fields: ["questionID", "questionsetID"]) @auth(rules: [{allow: private}, {allow: private}]) { id: ID! questionsetID: ID! questionID: ID! questionset: QuestionSet! @connection(fields: ["questionsetID"]) question: Question! @connection(fields: ["questionID"]) } `
@kenchoong this is just a workaround for a bug. Fix is going out soon.
@martinrojas can you verify if it worked after moving your Enums to the end of the schema? They should be at the bottom of the console output if they're at the end.
@letsbelopez This worked thank you
Describe the bug A clear and concise description of what the bug is.
Failed to create Many-to-Many Relationship between 2 model. It always state 1:n relationship in Admin UI
To Reproduce Steps to reproduce the behavior or terminal output if applicable
2 model here,
Product
andOrder
Then I click Add relationship in
Order
, then selectProduct
andMany-to-Many Relationship
as shown in this imageEnd up appear in
Order
model like this:And unable to select M:n relationship from the dropdown
Expected behavior A clear and concise description of what you expected to happen.
When Create the Many to Many relationship from Order with Product, both model will have M:n relationship presented. like this one I tried in Sandbox
Screenshots If applicable, add screenshots to help explain your problem.
Amplify CLI Version (if issue tied to Amplify CLI) You can use
amplify -v
to check the amplify cli version on your systemnode -v
to check the node version on your system : v12.18.2Additional context Add any other context about the problem here.
Not only cannot create in Amplify admin, it also unable to create M:n relationship from CLI.. More details here: https://github.com/aws-amplify/amplify-js/issues/8139
Please advise