React Admin: Can I use another field for <ReferenceInput>, other than "id"?

Ross

Is there any way to use a different reference field (other than id) for a ReferenceInput?

For example:
I have a languages resource, which I want to populate using a language_code field.
Note, I don't want to use the id field of languages, I want to use the code field.

I have managed to get it to work by using the following:

<ReferenceInput 
  label="Language code" 
  source="language_code" 
  reference="languages"
>
  <SelectInput optionText="name" optionValue="code" />
</ReferenceInput>

The only problem with this is that:

After selecting a language from the select input, the ReferenceInput tries to fetch the resource using the code field rather than the id field, which returns a 404 error.

Gildas Garcia

The value stored as the reference to the languages in the resource must be its identifier. Indeed, if you add a ReferenceField in the show view of your resource, how can it fetch the language without its id ?

You have two options here:

  • make your API support the languages/en route
  • store the language_id in addition to the language_code in your resource and create a custom ReferenceInput which will return both values after selection

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to format the text of the choices in a ReferenceInput field in react-admin?

Can I use another port other than 443 for SSL communication?

Use path parameter for ReferenceInput instead of query parameter for react-admin

Use Class Field Other than ID or Slug in URL

(laravel) Is it possible to use method injection by passing a field other than the id?

How can I make ssh-copy-id use a port other than 22?

Can I customize the `resources` helper in my routes to use a parameter other than \:id?

Can I use other prefixes other than 'is' in WCMUsePojo boolean getters?

Should I use properties (other than props or state) in React?

Can I use language other than English for default resources?

Can I use CircleCI with other OS than Ubuntu?

Can I use an environment other than 'test' for Ember tests?

is there any other than querySelector and querySelectorAll that i can use

Can I use Github for projects other than programming?

How can I set the field value in django admin based in another field's lookup?

In DRF, can we use other field than the primary field for a related model?

React-admin: <ReferenceInput> doesn't work with custom dataProvider

How to reference by a field other than id?

how to search other field than id

Can I use gsub to recursively replace all fieldnames with another field?

Logstash - grok use a field other than message

How can I use react router with a path of more than on / (no params)

Can I use other login method other than defaults in DC/OS

How can i use in laravel other cipher other than the standards AES-128, AES-256?

Can I get the data in v-text-field with a method other than v-model?

Can I use prePersist/preUpdate in Sonata Admin controller to persist more than one object?

Is it possible to reference another field than the id field in messages and titles?

Use a different value other than id

Can I use a directive to calculate field value based on other field value?