0

a simple table:

ID, NAME, POST_ID, GROUP_ID

either POST_ID or GROUP_ID must be set, but never both of them, NEITHER none of them. So,

there are valid cases:

ID, NAME, POST_ID, GROUP_ID
x,   y,   1,       NULL
x,   y,   NULL,    4

and NOT VALID cases:

ID, NAME, POST_ID, GROUP_ID
x,   y,   NULL,    NULL
x,   y,   4,       4

is it possible to set such complicated restriction rule?

John Smith
  • 101
  • 1

1 Answers1

1

I don't think it's possible. I would catch such cases in the front-end where the user enters the data. Also, you can perhaps replace both fields with two other fields:

A category field of type enum with possible values 'post' or 'group' A reference field containing the ID.

That way you can easily demand both to be non-empty and you can only reference a post ID or a group ID.

Tommiie
  • 5,547
  • 2
  • 11
  • 45