MrHertal / react-admin-amplify

AWS Amplify data provider for react-admin.
MIT License
159 stars 42 forks source link

Many to many input not working as expected #49

Closed arealmaas closed 3 years ago

arealmaas commented 3 years ago

I have the following schema:

type Organization
    @model {
    id: ID!
    name: String!
    benefitPartners: [OrganizationBenefitPartner]
        @connection(keyName: "byOrganization", fields: ["id"])
}

type OrganizationBenefitPartner
    @model(queries: null)
    @key(
        name: "byOrganization"
        fields: ["organizationId", "benefitPartnerId"]
        queryField: "listOrganizationBenefitPartnerByOrganizationId"
    )
    @key(
        name: "byBenefitPartner"
        fields: ["benefitPartnerId", "organizationId"]
        queryField: "listOrganizationBenefitPartnerByBenefitPartnerId"
    ) {
    id: ID!
    organizationId: ID!
    organization: Organization! @connection(fields: ["organizationId"])
    benefitPartnerId: ID!
    benefitPartner: BenefitPartner! @connection(fields: ["benefitPartnerId"])
}

type BenefitPartner
    @model {
    id: ID!
    name: String!
    organizations: [OrganizationBenefitPartner]  @connection(keyName: "byBenefitPartner", fields: ["id"])
}

To edit the many to many relation I have the following:

import {
    ReferenceManyToManyInput,
    ManyToManyReferenceContextProvider,
} from '@react-admin/ra-relationships';

<Edit {...props} title="Benefit partners" transform={propsToBeUpdated}>
    <ManyToManyReferenceContextProvider>
        <SimpleForm>
            <TextInput source="name" />
            <ReferenceManyToManyInput
                source="id"
                reference="organizations"
                through="OrganizationBenefitPartner"
                using="benefitPartnerId,organizationId"
                fullWidth
                label="Organization"
                validate={required()}
            >
                <SelectArrayInput optionText="name" />
            </ReferenceManyToManyInput>
        </SimpleForm>
    </ManyToManyReferenceContextProvider>
</Edit>

I'm using the new ra-relationships-package.

  1. When opening the edit-screen I don't see the values for the many to many relation. But if I click on the dropdown, the values I can choose from actually shows up and have the correct data. No idea why it doesn't appear in the input as the benefit partner has organizations.
  2. When saving the content I get the following error message: Could not find query createOrganizationBenefitPartne. Which should be 'createOrganizationBenefitPartner'. Does it try to un-pluralise the table by removing the last letter?

Anything I'm missing here? Some pointers would be much appreciated

MrHertal commented 3 years ago

Hi @arealmaas,

Enterprise edition modules are currently not supported since I personally did not subscribe :) PR are welcome if you want to add a feature.

I think ReferenceManyToMany is supported thanks to https://github.com/MrHertal/react-admin-amplify/pull/14

arealmaas commented 3 years ago

Ok, thank you for the quick response :)

arealmaas commented 3 years ago

I think we might come up with a PR eventuelly yes.