Allow a target prop in ReferenceField
See original GitHub issueIs your feature request related to a problem? Please describe. Consider
const CommentShow = props => (
<Show {...props}>
<SimpleShowLayout>
<TextField source="id" />
<ReferenceField source="post_id" reference="posts">
<TextField source="title" />
</ReferenceField>
<TextField source="author.name" />
<DateField source="created_at" />
<TextField source="body" />
</SimpleShowLayout>
</Show>
);
In some database all primary keys are named id
instead of [table_name]_id
. I’m not saying having id
as pk’s is recommendable, but it is used quite often.
Describe the solution you’d like
How about allowing a target
in ReferenceField
? Just like ReferenceManyField
is accepting both source
and target
.
const CommentShow = props => (
<Show {...props}>
<SimpleShowLayout>
<TextField source="id" />
<ReferenceField source="post_id" target="id" reference="posts">
^^^^^^^^^^^
<TextField source="title" />
</ReferenceField>
<TextField source="author.name" />
<DateField source="created_at" />
<TextField source="body" />
</SimpleShowLayout>
</Show>
);
Describe alternatives you’ve considered /
Additional context /
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:8 (6 by maintainers)
Top Results From Across the Web
The ReferenceField Component - React-admin
With this configuration, <ReferenceField> wraps the user's name in a link to the related user <Edit> page. Props. Prop, Required, Type, Default, Description ......
Read more >Allow multiple target entity types in the entity reference field
Problem/Motivation see [#2407505] We want to be able to reference any entity from a menu link (except other menu links!)
Read more >React-Admin | Bulk-Select with ReferenceField
I believe this is because the onToggleItem prop is normally provided by the List component, however in this application, Datagrid doesn't have a ......
Read more >Reference field type
Reference fields store a list of each user's recent selections to allow users to quickly select past values when filling in a reference...
Read more >8 - Programmatically update an entity reference field
Like in D7 the main property of a reference field in D8 is still the target id : $node->field_code_used_by->target_id = $user_id;.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No problem. I hadn’t considered translating in the dataProvider. Thanks for the suggestion.
Btw, you guys are awesome! I had this Datagrid with overly nested ReferenceManyFields and ReferenceFields. And it worked flawlessly. Really amazing what you are building! Again, 👏👏👏.
@fzaninotto, I’m gitting the same constraints as many others, trying to add a ReferenceField to Datagrid in order to pull in data from another table on composite id or just any foreign key that’s not id. I’d be most fine adding some translation logic in my dataprovider to do so, but lacking the ability to send any options to the dataprovider from the ReferenceField component.
useGetManyAggregate does pass along meta to the dataprovider, but there’s no way to send em through via ReferenceField component + useReference hook. I did an implementation in my codebase, but had to import 400 lines of code just to add 1 prop (=meta) to ReferenceField + the same prop to useReference.
A big win would be the ability to set meta={…} props on ReferenceField that would be sent along to the dataprovider.