title: Save multiple fields from record in different collection in react-admin Form
body: <p>I'm using <code>react-admin</code> to manage a MongoDB database. A simplified example of the collections in the database:</p>
  <pre class="lang-json prettyprint-override"><code>contacts = [
      { id: 8, name: &quot;Joe&quot;, country: &quot;UK&quot; },
  ]
  
  tasks = [
      { id: 0, description: &quot;&quot;, dev: { contact_id: 8, name: &quot;Joe&quot; } },
  ]
  </code></pre>
  <p>The documents in <code>tasks</code> have to store both <code>contact_id</code> (contact doc reference) and <code>name</code> (shown in many different views, so the number of API calls can be reduced). In this case, I'd use an <code>AutocompleteInput</code> within a <code>ReferenceInput</code> to save <code>contact_id</code>.</p>
  <pre class="lang-js prettyprint-override"><code>&lt;ReferenceInput source=&quot;dev.contact_id&quot; reference=&quot;contacts&quot;&gt;
      &lt;AutocompleteInput
          source=&quot;dev.contact_id&quot;
          optionText=&quot;name&quot;
          optionValue=&quot;id&quot;
      /&gt;
  &lt;/ReferenceInput&gt;
  </code></pre>
  <p>However, once the contact is selected in the <code>Autocomplete</code>, I can't find a way to save the field <code>name</code>, so the <code>task</code> document looks like in the example. So far I've tried getting the <code>contact</code> record and adding the <code>name</code> field before submitting the form, but it's not working (hooks can only be called inside the body of a function component):</p>
  <pre class="lang-js prettyprint-override"><code>export const TaskForm = ({ children }) =&gt; {
      const { handleSubmit } = useForm()
  
      const onSubmit = async (data) =&gt; {
          const contact = await useGetOne('contacts', { id: data?.dev?.contact_id })
          console.log(contact)
      }
      return (
          &lt;Form onSubmit={handleSubmit(onSubmit)}&gt;
              {children}
          &lt;/Form&gt;
      )
  }
  </code></pre>
  <p>Any suggestions?</p>