Skip to content

ReferenceManyCount

Displays number of related records for a ReferenceMany relation.

Use <ReferenceManyCount> anywhere inside a RecordContext. You must set the reference and target props to match the relationship:

  • reference is the name of the related resource to fetch (e.g. comments)
  • target is the name of the field in the related resource that points to the current resource (e.g. post_id)
import { ReferenceManyCount } from '@/components/admin';
// display the number of comments for the current post
<ReferenceManyCount reference="comments" target="post_id" />

It counts the number of comments related to the current post, where post_id in the comments resource matches the current post id, using dataProvider.getManyReference() with a pagination of { page: 1, perPage: 1 }.

You can get a count of a subset of the related records by passing a filter prop:

// display the number of published comments for the current post
<ReferenceManyCount
reference="comments"
target="post_id"
filter={{ published: true }}
/>
PropRequiredTypeDescription
referenceRequiredstringTarget resource name
targetRequiredstringForeign key field in target resource
filterOptionalobjectExtra filter values
linkOptionalbooleanMake count a link
recordOptionalRaRecordRecord providing id (from context if omitted)
sourceOptionalstringSource field of current record (default id)