I\'m creating a website in which I will be managing users and their permissions. I am looking to implement user roles, and can\'t seem to wrap my head around how things shou
We have managed with two table using json datatype so we does not need any repeating entry like
Role_ID Permission_ID
1 1
1 2
Role Table
id, role_name
'1', 'read'
'2', 'write'
'3', 'update'
'4', 'all'
User Table
id, name, role_assign, role_type
'1', 'arjun', '[1, 2]', 'admin'
'2', 'dhruv', '[3, 4]', 'user'
Query
SELECT u.id,r.role_name,u.name FROM test.users u inner join
test.role r on JSON_CONTAINS(u.role_assign, cast(r.id as json));
Output
id, role_name, name
'1', 'read', 'arjun'
'1', 'write', 'arjun'
'2', 'update', 'dhruv'
'2', 'all', 'dhruv'