I have and enpoint that returns Locality objects and every Locality object have a river_basins property that is an array of River Basins objects like this:
// Locality record
{
"id": 290,
"name": "asas",
"description": "agsdg",
"status": true,
"district": {
"id": 10108,
"name": "Huancas",
"ubigeo": null,
"status": true
},
"river_basins": [
{
"id": 5,
"name": "Inambari",
"status": true
},
{
"id": 10,
"name": "Río Apurimac",
"status": true
},
{
"id": 12,
"name": "Río Aushiri",
"status": true
}
]
}
In the react-admin Locality List page, the RiverBasin objects are rendered like this using the <ReferenceArrayField />
:
using the following code:
export const LocalityList = (props) => (
<List {...props}>
<Datagrid>
<TextField source="id" />
<TextField source="name" />
<TextField source="description" />
<ReferenceField
reference="districts"
source="district.id"
label="District"
>
<TextField source="name" />
</ReferenceField>
<ReferenceArrayField
reference="river-basins"
source="river_basins"
label="River basin"
>
<ArrayField source="river_basins" label="River basins">
<SingleFieldList>
<ChipField source="name" />
</SingleFieldList>
</ArrayField>
</ReferenceArrayField>
<BooleanField source="status" />
</Datagrid>
</List>
);
But when trying to show the RiverBasins object with a select component in the react-admin Edit page it does not show any preselected items:
here’s the code i use for the react-admin Edit page:
export const LocalityEdit = (props) => (
<Edit {...props}>
<SimpleForm>
<ReferenceArrayInput
source="river_basins"
reference="river-basins"
label="River basin"
></ReferenceArrayInput>
</SimpleForm>
</Edit>
);
and when i change the source property to any other word than river_basins, i get no getMany function call.
What am i doing wrong? do i need to change the api response? because when i activate the loadRelationIds: true
in my endpoint the select component works as expected:
but in my team we all decided we need the complete object relation in the response instead of jus the id, so acivating the loadRelationIds
is not an alternative.