This repository was archived by the owner on Sep 24, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +49
-1
lines changed Expand file tree Collapse file tree 7 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,7 @@ class Film < ApplicationRecord
88 join_table : 'films_people' ,
99 foreign_key : 'film_id' ,
1010 association_foreign_key : 'person_id'
11+
12+ has_many :ratings
13+ has_many :users , through : :ratings
1114end
Original file line number Diff line number Diff line change 1+ class Rating < ApplicationRecord
2+ belongs_to :user
3+ belongs_to :film
4+ end
Original file line number Diff line number Diff line change 1+ class User < ApplicationRecord
2+ has_many :ratings
3+ has_many :films , through : :ratings
4+ end
Original file line number Diff line number Diff line change 1+ class CreateRatings < ActiveRecord ::Migration [ 5.0 ]
2+ def change
3+ create_table :users do |t |
4+ t . string :name
5+ t . timestamps
6+ end
7+
8+ create_table :ratings do |t |
9+ t . belongs_to :user , index : true
10+ t . belongs_to :film , index : true
11+ t . integer :rating
12+ t . timestamps
13+ end
14+ end
15+ end
Original file line number Diff line number Diff line change 1010#
1111# It's strongly recommended that you check this file into your version control system.
1212
13- ActiveRecord ::Schema . define ( version : 20170211182808 ) do
13+ ActiveRecord ::Schema . define ( version : 20170212195638 ) do
1414
1515 create_table "films" , force : :cascade do |t |
1616 t . string "title"
103103 t . datetime "updated_at" , null : false
104104 end
105105
106+ create_table "ratings" , force : :cascade do |t |
107+ t . integer "user_id"
108+ t . integer "film_id"
109+ t . integer "rating"
110+ t . datetime "created_at" , null : false
111+ t . datetime "updated_at" , null : false
112+ t . index [ "film_id" ] , name : "index_ratings_on_film_id"
113+ t . index [ "user_id" ] , name : "index_ratings_on_user_id"
114+ end
115+
106116 create_table "species" , force : :cascade do |t |
107117 t . string "name"
108118 t . string "classification"
137147 t . datetime "updated_at" , null : false
138148 end
139149
150+ create_table "users" , force : :cascade do |t |
151+ t . string "name"
152+ t . datetime "created_at" , null : false
153+ t . datetime "updated_at" , null : false
154+ end
155+
140156 create_table "vehicles" , force : :cascade do |t |
141157 t . string "name"
142158 t . string "model"
Original file line number Diff line number Diff line change 1+ good-rating :
2+ user : test-user
3+ film : a-new-hope
4+ rating : 5
Original file line number Diff line number Diff line change 1+ test-user :
2+ name : xuorig
You can’t perform that action at this time.
0 commit comments