panter / ra-data-prisma

Packages to connect react-admin with prisma version 2
MIT License
84 stars 28 forks source link

How To Use connectOrCreate In ReferenceInput ? #84

Closed winner106 closed 3 years ago

winner106 commented 3 years ago

after using ra-data-prisma , saved me a lot of time! thanks a lot!

what I expected

I have a one to many model(eg: customers - orders), when I want to create a record in the orders table , the logic is : " if the customerId is exists, then connect , else create "

I tried this , but failed

const OrderCreate = (props) => (
  <Create {...props}>
    <SimpleForm>
      <ReferenceInput label="Product Name" source="product" reference="Product">
        <SelectInput optionText="name" />
      </ReferenceInput>
      <ReferenceInput source="customer.connectOrCreate" reference="Customer" label="Email" filterToQuery={(searchText) => ({ email: searchText })}>
        <AutocompleteInput optionText="email" />
      </ReferenceInput>
      <NumberInput source="permitUsers" label="permitUsers" initialValue={3} />
      <DateInput source="orderDate" label="orderDate" initialValue={new Date()} />
    </SimpleForm>
  </Create>
);

the browser request payload:

image-20210820202851233

my backend api service connectOrCreate can work

image-20210820201745011