Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceField inside Edit component is not requesting getMany #4124

Closed
dustin-rcg opened this issue Dec 6, 2019 · 4 comments · Fixed by #4147
Closed

ReferenceField inside Edit component is not requesting getMany #4124

dustin-rcg opened this issue Dec 6, 2019 · 4 comments · Fixed by #4147
Assignees
Labels

Comments

@dustin-rcg
Copy link

dustin-rcg commented Dec 6, 2019

What you were expecting:
ReferenceField in Edit component causes a getMany request to be sent to data provider for the referenced resource, and the value is displayed by the child field.

What happened instead:
No getMany request is sent to the data provider for the reference resource.

Steps to reproduce:
Create a vanilla react-admin project by following the first few steps of the tutorial.
Create a list and edit form for a resource and add the resource under the Admin component.
In the edit form, add a ReferenceField component with a child TextField. Add the referenced resource under the Admin component.
In your data provider, add some console.log statements so you can see which requests react-admin makes to the data provider.
Run the project. Go to the browser window that opened and also open developer tools to javascript console.
Select an item from the list in the app to view the edit form.
Look in the console output and see that no getMany request is made.
Replace the ReferenceField with a ReferenceInput, and the TextField with a TextInput.
Save the changes, and the app reloads. In the console, you will now see both a getMany and a getList for the referenced resource.
Apparently, ReferencField inside an Edit component does not generate a getMany request as advertised: "Such components are used in the List view, but you can also use them in the Edit and Create views for read-only fields....This component fetches a single referenced record (using the GET_MANY REST method), and displays one field of this record." (https://marmelab.com/react-admin/Fields.html)

Related code:

Example edit form:

export const InvestmentEdit = props => (
  <Edit {...props}>
    <SimpleForm variant="outlined">
      <ReferenceField label="Fund AUM" source="id" reference="aumLast">
        <TextField source="FundAUM" />
      </ReferenceField>
    </SimpleForm>
  </Edit>
);

In this example the source is id because the referenced resource has a one-to-one relationship to the edited resource.

Confirmed that I have the corresponding investment and aumLast resources defined as children of my Admin component. Also confirmed that the corresponding query directly on the database returns data.

Other information:

Environment

  • React-admin version: 3.0.3
  • Last version that did not exhibit the issue (if applicable): N/A
  • React version: 16.12.0
  • Browser: Google Chrome Version 78.0.3904.108 (Official Build) (64-bit)
  • Stack trace (in case of a JS error): N/A
@akbkk
Copy link

akbkk commented Dec 9, 2019

I'm having the same issue. I don't see any requests firing.
I tried setting up record / resource / basePath explicitly, didn't help.
Also, ReferenceArrayField nearby is working properly.

@djhi
Copy link
Collaborator

djhi commented Dec 9, 2019

In order to fix the issue, we need to reproduce it. Please share a codesandbox showing the issue.

@dustin-rcg
Copy link
Author

@djhi I created a sandbox here: https://codesandbox.io/s/cocky-star-fiti9?fontsize=14&hidenavigation=1&theme=dark

If you click on the animal in the list, it takes you to the edit form. You can see that the ReferenceField does not load the data, but the ReferenceInput for the exact same data is loaded. If you look at the console, you will see that no getMany is called for the ReferenceField. (Comment out the ReferenceInput to make this really obvious.)

@fzaninotto
Copy link
Member

Confirmed and reproduced, thanks for the CodeSandbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants