Rails modeling headache

36 views Asked by At

I am in the process of building a Rails app that will let logged-in users:

  • create multiple agendas
  • access each agenda through a "month" view
  • add events to each month
  • share each agenda (through a link) with other logged-in users, who will see it with the same default "month" view but will be able to access other months with the simple click of a previous/next button.

The first thing I am trying to do is defining Rails models, and here is my dilemma:

1. Should I go with four models:

  • User model (has_many agendas)
  • Agenda model (belongs to many users, has many months)
  • Month model (belongs to one agenda, has many post)
  • Post model (belongs to one month)

2. OR should I go with three models:

  • User model (has_many agendas)
  • Agenda model (belongs to many users, has many posts)
  • Post model (belongs to one agenda)

Indeed, the months will not be specific to each agenda, but will only be a framework to display posts month per month in each agenda.

What do you think?

1

There are 1 answers

5
rxing On BEST ANSWER

It depends on whether you have many fields specific to agenda (not to month). If you do, it's better to have one separate model for agenda.

BTW, It seems user and agenda are many-to-many relationship. In this case, you need one intermediate model between user and agenda.