I have seen similar queries on how to solve this, but I did not find precisely this case in particular.
I have a custom type called "workspaces" that I have to relate to users. A "workspace" can be assigned many members (users) and a user can be a member of many "workspaces".
Because you can not establish custom type relationships with users directly, I thought to do the following:
Create the custom type "workspaces" and another one called "members" with the custom fields ("ID", "name" and "last name") and create a parent / child relationship where "workspace" is a parent and "members" is son.
When creating a new user with CRED from the front end, use the "cred_save_data" hook to also save the "ID", "name" and "surname" of the user in the custom type "members", in order to assign many members to workspaces.
Then, when you create a new workspace, you can assign the members you want from a list and when you enter to see a workspace, get the related members through the "ID" field, with "ID" of users.
So that in this way, you can maintain the relationships between workspaces and members (users), and then manipulate the views.
This is a good way to solve it?
If so, what style would have the function to be able to save the 3 user fields in the fields of the custom type members? Keep in mind that the fields belonging to members must also be updated when a user is edited (first and last name) and when it is deleted.
Thanks in advance.
Yes, this is a good way to achieve it.
Keep in mind that if you want a many to many relationship (many users can belong to many workspaces, and vs), you cannot yet do that with Toolset.
You would need an Intermediary Post Type that connects your Data. But that is a detail of organization and display, it does not affect how you update your Posts with User Data.
To Update a Post with User data, you use the cred_save_data() function.
You get the data from the $_POST variable of the CRED Form.
Then you use wp_insert_post() to insert a new post with this data through the cred_save_data() action.
https://developer.wordpress.org/reference/functions/wp_insert_post/
After you can run a update_post_meta() on this new Post so to pass the new user data to the fields
https://codex.wordpress.org/Function_Reference/wp_update_post
For the Edit part you just apply a new cred_save_data() that does NOT have a wp_insert_post() (since the post exists already) but only the needed update_post_meta().
Here you can see a working example of such a code:
https://pastebin.com/2BTbVbcs