I have 3 entities

`teacher` : Stores the name of a teacher in the school. (e.g "teacher 1", "teacher 2")  

`access` : Stores the name of all types type of access possible. (e.g "class\_teacher", "sports\_teacher", "head\_master")  

`classroom`: Stores the name of different classes in the school. (e.g. "classroom I", "classroom II")

The relationships are as follows:

* teacher <-> access is many-to-many
* teacher <-> classroom is many-to-many

The way I have modelled it right now is in following tables

1. Teacher (id, username) (1 t1, 2 t2)
2. access (id, access) (1 a1, 2 a2)
3. classroom (id, class) (1 c1, 2 c2)
4. teacher\_access (id, teacherId, accessId) (1 1 1, 1 1 2)
5. teacher\_classroom (id, teacherId, classroomId) (1 1 1, 1 1 2)

A row in teacher\_access stores the specific "access" a specific "teacher" has.  

e.g. (1 1 1) shows that t1 has access a1

A row in teacher\_classroom allows a specific "teacher" to access a specific "classroom" using the accesses he/she has.  

e.g. (1 1 1) shows that teacher t1 has access to classroom c1

The problem here is that I don't want to give teacher t1 access a2 for classroom c2.

In my current design, if there is a row in teacher\_access, the tId in that row will have the "access" specified by this row's aId for all the classrooms for which we have a row in "teacher\_classroom" having the same teacherId. So, if I have 2 rows in "teacher\_access" with (tId =1, aId = 1), (tId = 1, aId = 2) and 2 rows in "teacher\_classroom" with (tId =1, cId =1),(tId = 1, cId = 2), "teacher"(1) has both "accesses"(1,2) for both "classrooms"(1,2). But what I want to do is provide only aId(1) to tId(1) for cId(1) and both aId (1,2) for cId (2) tId : teacherId aId : accessId cId: classroomId.

What I am trying to say is I want a "teacher" to have different "accesses" to different "classrooms". E.g. A teacher can have both "class\_teacher" and "sports\_teacher" access to classroom "classroom I" and only "sports\_teacher" access to "classroom II". I am unable to do this using my current design because if a teacher has "access" (sports\_teacher, class\_teacher) per teacher\_access and the same teacher has access to "classroom" (classroom I, classroom II), I cannot have the teacher as only "sports\_teacher" for "classroom II".

What is a better way to model?