#one to one relationship field.

21 messages · Page 1 of 1 (latest)

velvet sparrow
#

I have to collection. users and consultants. I would like to have relationship field in both where every consultant belong to one user and every user belong to one consultant. Is there a way I can make this bend with managing this manually?

sweet quailBOT
icy geyser
#

You can do this with hooks. With afterChange hooks on each collection, when the user is updated on the consultant collection, use payload.update to update the users collection with the consultant (the doc that triggered this afterChange hook).

#

You could implement this on both ends, if you think it is necessary - not sure how your system will work and how users and consultants get assigned

velvet sparrow
#

I'm doing exactly this and I will leave my code here for reference but I wished if there is an easier and more dynamic way but thank you.

#

if you think it's possible to implement a dynamic way. Please give me brief guidance and I will not mind to put sometime to push a PR.

icy geyser
#

What do you mean by dynamic?

velvet sparrow
#

Hello @icy geyser Refer to the blog from Strapi please https://strapi.io/blog/understanding-and-using-relations-in-strapi. There are different type of relationships that it can be used to have different relationship behaviors. It will make the config simple and more readable. I will post my code in a bit in Payload to create similar relationship behaviors in Payload.

velvet sparrow
#

I decided to give up on this. It proof so hard to keep only one user assigned to one consultant document only and one user to one consultant. Relationship field have to improve. I still like Payload but more have to be done. I'm trying to mimic a system from work to replace Strapi.

icy geyser
#

But you could mimic it by adding your own like we talked about above?

velvet sparrow
#

It proof very time consuming for proof-concept project.

#

Here is a video demonstrate how it works in Strapi. I don't like the visual editor as it make it hard to trance changes but Payload collection configuration must have something easy to reference the other document. one more option under the relationship field called reference: true should solve it.

#

I decided to take the opportunity to check Tabs but I notice I can't save each tab independently of each other. This make more chores to be done regarding validations.

#

It's how I decide to go around it but now I can't use options like required as it will be required for all users disregarding their roles.

icy geyser
#

Yeah I definitely see what you mean

#

hmmmm

#

probably some good feature requests in here

velvet sparrow
#

After I removed my consultants collection from PayloadConfig file. It break the admin panel from accessing another collection called consultations because of relationships that used to exists to link consultation to consultant. I had to go to the database and remove these fields manually. Just leaving that here to help you guys making something great!

#

yess. In real life it's rarrly data don't link to each other. I worked with headless system and CMS for along time. I ensure guys it's important but you are in the right track. You are into something bigger than just headless CMS.

icy geyser
#

oh totally, I am not trying to disregard the importance of the relationships. We are just in the middle of adding PG db support so I am not sure when we would look at something like you are requesting

velvet sparrow
#

I totally understand. I'm just checking Payload and leaving my thoughts here