Add ability to omit basePath in Reference fields #6028
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using a Field component outside of a Datagrid or a Form, users have to inject props manually. They can understand that they must inject
record
andresource
, but they often forget to injectbasePath
. It is not a problem, except for Reference fields, where thebasePath
is used to build the links to the related records. Using these Fields without abasePath
leads to a cryptic error:The
basePath
property isn't well documented, and to be honest, it isn't very useful. In the most common case, thebasePath
equals/${resource}
.Solution
If the
basePath
isn't set, use the resource name instead. That way, users can omit thebasePath
when usingReferenceField
,ReferenceArrayField
, andReferenceManyField
manually.<ReferenceField resource="comments" record={data[id]} source="post_id" reference="posts" - basePath="/comments" > <TextField source="title" /> </ReferenceField>