How to design / model a has many relationships that have a meaningful join table?

I could not articulate the words (in the title of the question), which I am trying to do, therefore, in honor of saying that an image is worth a thousand words; In short, what I'm trying to do is ...

enter image description here

Basically, I have a Teacher has many Assignments and a Student has many Assignments , which roughly corresponds to:

enter image description here

I try to avoid using the has_and_belongs_to_many macro, because my meeting model has some value (operation), for example, it has a logical field: confirmed.

So, I was thinking about using the has_many macro : through and maybe using the Assignable table model? What do you guys think?

The script I'm trying to execute is simple,

  • Student requests meeting with teacher on specific dates / times
  • If Teacher is available (and wants to give a lesson at this date / time), she confirms the appointment.

I hope you tell me how you would approach this problem? Is my assumption about using has_many: through a macro correct?

Thanks!

+6
source share
1 answer

Both teachers and students could inherit one class, for example. Man. Then create a connection between Person and Appointments. Thus, you keep the architecture open so that in the future you want to add “Parents”, then they can be easily integrated and can participate in meetings.

Perhaps it’s not entirely clear how you join the classes of children (students, parents, teachers). This may be due to polymorphic relationships, which I especially don't like. You must leave with a single join table.

In any case, you want to design so that your system can be expanded. Some extra work early will save you a lot of work later.

+1
source

All Articles