Search code examples
ruby-on-railsmodeltable-relationships

ROR Model Setup Question: Table Relationships


I'm developing a site that will have a model for users, a model for submissions, and a model for ratings. Each submission may have only one rating per user. My question is how should I set this up in my models?


Solution

  • class Submission
      has_many :ratings
      validates_uniqueness_of :rating, :scope => :user_id
    end