Skip to content

How to get relationship field's targeted collection in Admin UI #891

Answered by jmikrut
khakimvinh asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @khakimvinh — I'm following what you are looking to do.

I would avoid changing the fields to multiple like you said, because like you noticed, that changes the shape of the data. You probably want your plugin to handle all four types of relationship field data.

You can access the config for the collection you're working in, and find the relevant field that corresponds to the field that you're interacting with.

// import the hook
import { useConfig } from 'payload/components/utilities';

// use it in your React component
const config = useConfig();

Could you do that? To find the field recursively, you would need to parse the field's path that you are trying to work with. For example, t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@khakimvinh
Comment options

Answer selected by khakimvinh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants