Reputation: 131
I have a Postgres table log_actions with fields:
id - id of the action
userId
action - BAN, ADD_PROCESS, etc...
action_id
action_id is the id from one of the following tables:
user_bans for action=BAN
user_processes for action=ADD_PROCESS
Upvotes: 0
Views: 516
Reputation: 1270683
This is a viable structure for handling "one-of" relationships. As Jon points out, you cannot declare foreign key relationships. That is a shame, so this is not a great solution.
Postgres offers table inheritance. This probably does exactly what you want. The "action" tables can all inherit actionid
from an actions
table. This can be used for the join. Each table can then have its own specific columns (and foreign key relationships).
Refer to the documentation for more information about inheritance.
Upvotes: 1
Reputation: 294
I'd advise against such a design, because it precludes the use of foreign keys for integrity control. (You may want to look into entity subclassing.) It also looks as if you have a normalisation issue in that action_id
seems to functionally determine action
without being a superkey.
Upvotes: 1