This seems like a desirable feature but I can't seem to figure out how I would do it while the foreign key is a part of the primary key (composite key).
The table is a simple junction table for a many to many relationship referencing User.id
and Access.id
referencing functions a user has access to:
Column | References
user user.id
access access.id
Therefore there can be many entries for each user and each access level. To simplify things for "superusers" I wanted to have a NULL
value for access
which would mean they have access to every page (this is the only way I could figure how to enter a value that didn't reference a row in the access
table). The problem is MySQL won't allow a NULL
value as a part of the primary key.
Is there a way around the NULL
issue with primary keys or is there another way to reference every row (or no rows) in a foreign key? The only other way around this I can think of would be to disable the foreign key or have to add a row for every access.id in the table. Either of which would be undesirable.