Need help modeling complex entity relationships

I'm attempting to create a simple web app that will allow users to do sentence completion exercises. We have users, stems (first part of sentences to be completed), stem-sets (a particular subset/collection of stems), and stem responses. It looks like the primary entities/tables/associations that I need are:

USERS has_and_belongs_to_many STEM_SETS

STEMS has_and_belongs_to_many STEM_SETS

STEM_SETS has_and_belongs_to_many USERS has_and_belongs_to_many STEMS


Not sure about which relationships the stem responses model should have. It seems like they should belong to the combination of USERS, STEMS and STEM_SETS.

If I were just creating the db table for this, I would have:

STEM_RESPONSES id user_id stem_set_id stem_id text

Is there a way to represent this with Rails relationships? Or am I missing a much easier way to do this?