react-admin: ReferenceField on self resource doesn't return data

Please do not submit support requests or “How to” questions here. For that, go to StackOverflow.

What you were expecting:

I have a table Organizations with the following fields

id parent_id name

The table contains the name of a organization and the parent id of a organization

I made a request to display the parent organization name

            <ReferenceField
                label={translate('resources.organization.parent')}
                source="parent_id"
                reference="organizations"
                translate={translate}
                sortable={false}
            >
                <Field source="name" />
            </ReferenceField>

This display nothing than return the parent organization name

On the Edit, I do this request:

            <ReferenceInput
                label={translate('resources.organization.parent')}
                source="parent_id"
                reference="organizations"
                translate={translate}
                validate={validateRequired}
            >
                <SelectInput optionText="name"/>
            </ReferenceInput>

It return the parent organization name, what I want.

What happened instead:

Infinite loop Steps to reproduce:

Related code:

insert short code snippets here
            <ReferenceField
                label={translate('resources.organization.parent')}
                source="parent_id"
                reference="organizations"
                translate={translate}
                sortable={false}
            >
                <Field source="name" />
            </ReferenceField>

Other information:

Environment

  • Admin-on-rest version: next
  • Last version that did not exhibit the issue (if applicable):
  • React version:
  • Browser:
  • Stack trace (in case of a JS error):

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (16 by maintainers)

Most upvoted comments

I suggest you look both at the console and at the documentation. The console shows an error in your code:

Failed prop type: The prop source is marked as required in TextField, but its value is undefined.

And if you look at the <ReferenceField> documentation, you’ll see that instead of using

<TextField optionText="name" />

as child, you should use

<TextField source="name" />

ReferenceField on self resource does return data, you’re just not using it correctly.

As for getting the children categories, it also works. Just try

            <ReferenceManyField
                reference="categories"
                target="parent_id"
                label="parent-many"
            >
                <SingleFieldList>
                    <TextField source="name" />
                </SingleFieldList>
            </ReferenceManyField>

I strongly advise against using a datagrid inside another datagrid. Use <SingleFieldList> instead.

Next time, please open a discussion for troubleshooting on StackOverflow, and make sure there is an actual bug before opening an issue here.