0

For example, I want to add a custom user metadata field for projects he is assigned to. But this field must have a foreign key constraint to another table to make sure that the project it is referencing, is valid.

Is there a way to handle this scenario with pure user metadata instead of creating an extra table to link the users with the projects?

0

You won’t be able to do this with meta. All user meta is stored in the meta_value column of wp_usermeta, so if you tried to set a constraint on that column you’d just prevent any other user meta from being set.

| improve this answer | |
0

You should be able to store the project id(s) as a string in the wp_usermeta table, but a constraint won't work since the meta_value column is used for many different things. Instead, database INSERT and UPDATE triggers could probably be used, though writing correct ones would take more work and thought than just quickly defining a foreign key constraint would.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.