question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow a target prop in ReferenceField

See original GitHub issue

Is 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:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
christiaanwesterbeekcommented, Jul 19, 2018

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, 👏👏👏.

1reaction
lauri865commented, Jul 6, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found