user3591126
user3591126

Reputation: 211

Basic rails database opinion needed

I'm building a teaching app that contains "courses". I would just like some opinions on the best way to store that the user completed the course.

I guess I could do a has_many to has_many courses to users. Is this the only way?

Upvotes: 0

Views: 24

Answers (1)

kobaltz
kobaltz

Reputation: 7070

I would have a separate model called Achievement where a userhas_many achievements and the courses has_many achievements. The Achievement model belongs to both the users and courses. This would allow for a boolean to determine if the course has been completed. You can also add extra attributes to this model where you can track the progress of the course.

Be sure to set the appropriate validators like

validates :user_id, :uniqueness => {:scope => :course_id} so that a user cannot enroll in the same course more than once (if that is a parameter of your courses).

Upvotes: 1

Related Questions