Skip to content
Permalink
Browse files

Complete updates

  • Loading branch information
ImsirovicAjdin committed Jan 3, 2020
1 parent 050ea85 commit 8ef2e711b4d6003ab604f6f72d8255fefbf1709c
@@ -1,7 +1,9 @@
class Movie < ApplicationRecord
# self.primary_key = 'id'

has_many :users
# has_many :users
has_and_belongs_to_many :users
has_many :movie_plot_updates

scope :from_newest, lambda { order("created_at DESC") }
scope :lookup, lambda {|titlestring| where(["title LIKE ?", "%#{titlestring}%"]) }
@@ -0,0 +1,6 @@
class MoviePlotUpdate < ApplicationRecord

belongs_to :user
belongs_to :movie

end
@@ -1,3 +1,5 @@
class User < ApplicationRecord
belongs_to :movie, {:optional => true} #, { :foreign_key => 'movie_id' }, dependent: :destroy # on_delete: :cascade
# belongs_to :movie, {:optional => true} #, { :foreign_key => 'movie_id' }, dependent: :destroy # on_delete: :cascade
has_and_belongs_to_many :movies
has_many :movie_plot_updates
end
@@ -0,0 +1,14 @@
class CreateTableMoviesUsers < ActiveRecord::Migration[6.0]
def up
create_table :movies_users, :id => false do |t|
t.integer "movie_id"
t.integer "user_id"
end
add_index("movies_users", ["user_id", "movie_id"])
end

def down
drop_table :movies_users

end
end
@@ -0,0 +1,15 @@
class CreateMoviePlotUpdates < ActiveRecord::Migration[6.0]
def up
create_table :movie_plot_updates do |t|
t.integer "user_id"
t.integer "movie_id"
t.string "description"
t.timestamps
end
add_index("movie_plot_updates", ["user_id", "movie_id"])
end

def down
drop_table :movie_plot_updates
end
end
@@ -10,11 +10,20 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_12_26_155147) do
ActiveRecord::Schema.define(version: 2020_01_03_101812) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "movie_plot_updates", force: :cascade do |t|
t.integer "user_id"
t.integer "movie_id"
t.string "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["user_id", "movie_id"], name: "index_movie_plot_updates_on_user_id_and_movie_id"
end

create_table "movies", force: :cascade do |t|
t.string "title", limit: 150
t.string "plot_description", limit: 300
@@ -23,6 +32,12 @@
t.datetime "updated_at", precision: 6, null: false
end

create_table "movies_users", id: false, force: :cascade do |t|
t.integer "movie_id"
t.integer "user_id"
t.index ["user_id", "movie_id"], name: "index_movies_users_on_user_id_and_movie_id"
end

create_table "users", force: :cascade do |t|
t.string "first"
t.string "last"
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
@@ -0,0 +1,7 @@
require 'test_helper'

class MoviePlotUpdateTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 8ef2e71

Please sign in to comment.
You can’t perform that action at this time.