fixed bugfix where another user could not store the same object again
fixed the primary keys => all the classes have now composite primary key which contais an id + user_id, necessary gem: 'composite_primary_keys' fixed the user_id relation => every class now "belongs_to" user pls kill me know
This commit is contained in:
parent
1e87036094
commit
ca38d7260d
3
Gemfile
3
Gemfile
@ -37,6 +37,9 @@ gem 'devise-encryptable', '0.2.0'
|
|||||||
# Reduces boot times through caching; required in config/boot.rb
|
# Reduces boot times through caching; required in config/boot.rb
|
||||||
gem 'bootsnap', '>= 1.4.2', require: false
|
gem 'bootsnap', '>= 1.4.2', require: false
|
||||||
|
|
||||||
|
# for composite primary keys
|
||||||
|
gem 'composite_primary_keys'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
||||||
|
|||||||
@ -36,9 +36,9 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController
|
|||||||
@project = TissCrawler.get_project_details(params)
|
@project = TissCrawler.get_project_details(params)
|
||||||
|
|
||||||
# create stores the object to the db after creation
|
# create stores the object to the db after creation
|
||||||
favorite_hash = {id: params[:id],
|
favorite_hash = {id: [params[:id], current_user.id],
|
||||||
# the user who is currently active
|
# the user who is currently active
|
||||||
user_id: current_user.id,
|
# user_id: current_user.id,
|
||||||
title: @project['titleDe']}
|
title: @project['titleDe']}
|
||||||
if FavoriteProject.create(favorite_hash).valid?
|
if FavoriteProject.create(favorite_hash).valid?
|
||||||
FavoriteProject.create(favorite_hash)
|
FavoriteProject.create(favorite_hash)
|
||||||
|
|||||||
@ -36,9 +36,9 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
|
|||||||
@thesis = TissCrawler.get_thesis_details(params)
|
@thesis = TissCrawler.get_thesis_details(params)
|
||||||
|
|
||||||
# create stores the object to the db after creation
|
# create stores the object to the db after creation
|
||||||
favorite_hash = {id: params[:id],
|
favorite_hash = {id: [params[:id], current_user.id],
|
||||||
# the user who is currently active
|
# the user who is currently active
|
||||||
user_id: current_user.id,
|
# user_id: current_user.id,
|
||||||
title: @thesis['title']['de']}
|
title: @thesis['title']['de']}
|
||||||
if FavoriteThesis.create(favorite_hash).valid?
|
if FavoriteThesis.create(favorite_hash).valid?
|
||||||
FavoriteThesis.create(favorite_hash)
|
FavoriteThesis.create(favorite_hash)
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
class FavoriteCourse < ApplicationRecord
|
class FavoriteCourse < ApplicationRecord
|
||||||
|
self.primary_keys = :id, :user_id
|
||||||
|
|
||||||
validates :title, :semester, :number, presence: true
|
validates :title, :semester, :number, presence: true
|
||||||
validates :semester, :number, uniqueness: {scope: [:semester, :number]}
|
validates :semester, :number, uniqueness: {scope: [:semester, :number, :user_id]}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class FavoritePerson < ApplicationRecord
|
class FavoritePerson < ApplicationRecord
|
||||||
self.primary_key = 'tiss_id'
|
self.primary_keys = :tiss_id, :user_id
|
||||||
|
|
||||||
validates :tiss_id, uniqueness: true
|
validates :tiss_id, uniqueness: { scope: [:user_id] }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class FavoriteProject < ApplicationRecord
|
class FavoriteProject < ApplicationRecord
|
||||||
self.primary_key = 'id'
|
self.primary_keys = :id, :user_id
|
||||||
|
|
||||||
validates :id, uniqueness: true
|
validates :id, :user_id, uniqueness: {scope: [:id, :user_id]}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class FavoriteThesis < ApplicationRecord
|
class FavoriteThesis < ApplicationRecord
|
||||||
self.primary_key = 'id'
|
self.primary_keys = :id, :user_id
|
||||||
|
|
||||||
validates :id, uniqueness: true
|
validates :id, :user_id, uniqueness: {scope: [:id, :user_id]}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,15 +1,13 @@
|
|||||||
class CreateFavoritePeople < ActiveRecord::Migration[6.0]
|
class CreateFavoritePeople < ActiveRecord::Migration[6.0]
|
||||||
def change
|
def change
|
||||||
create_table :favorite_people, id: false do |t|
|
create_table :favorite_people, primary_key: [:tiss_id, :user_id] do |t|
|
||||||
t.integer :tiss_id, null: false
|
t.integer :tiss_id, null: false
|
||||||
t.integer :user_id, null: false
|
t.belongs_to :user
|
||||||
t.string :first_name
|
t.string :first_name
|
||||||
t.string :last_name
|
t.string :last_name
|
||||||
t.string :picture_uri
|
t.string :picture_uri
|
||||||
t.string :personal_annotation
|
t.string :personal_annotation
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
add_index :favorite_people, :tiss_id, unique: true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
class CreateFavoriteCourses < ActiveRecord::Migration[6.0]
|
class CreateFavoriteCourses < ActiveRecord::Migration[6.0]
|
||||||
def change
|
def change
|
||||||
create_table :favorite_courses do |t|
|
create_table :favorite_courses , primary_key: [:id, :user_id] do |t|
|
||||||
|
t.integer :id
|
||||||
|
t.belongs_to :user
|
||||||
t.string :number, null: false
|
t.string :number, null: false
|
||||||
t.string :semester, null: false
|
t.string :semester, null: false
|
||||||
t.string :title, null: false
|
t.string :title, null: false
|
||||||
t.integer :user_id, null: false
|
|
||||||
t.string :personal_annotation
|
t.string :personal_annotation
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
add_index :favorite_courses, [:number, :semester], unique: true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
class CreateFavoriteTheses < ActiveRecord::Migration[6.0]
|
class CreateFavoriteTheses < ActiveRecord::Migration[6.0]
|
||||||
def change
|
def change
|
||||||
create_table :favorite_theses, id: false do |t|
|
create_table :favorite_theses, primary_key: [:id, :user_id] do |t|
|
||||||
t.integer :id, null: false
|
t.integer :id, null: false
|
||||||
t.integer :user_id, null: false
|
t.belongs_to :user
|
||||||
t.string :title
|
t.string :title
|
||||||
t.string :personal_annotation
|
t.string :personal_annotation
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
add_index :favorite_theses, :id, unique: true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
class CreateFavoriteProjects < ActiveRecord::Migration[6.0]
|
class CreateFavoriteProjects < ActiveRecord::Migration[6.0]
|
||||||
def change
|
def change
|
||||||
create_table :favorite_projects, id: false do |t|
|
create_table :favorite_projects, primary_key: [:id, :user_id] do |t|
|
||||||
t.integer :id, null: false
|
t.integer :id, null: false
|
||||||
t.integer :user_id, null: false
|
t.belongs_to :user
|
||||||
t.string :title
|
t.string :title
|
||||||
t.string :personal_annotation
|
t.string :personal_annotation
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
add_index :favorite_projects, :id, unique: true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
25
db/schema.rb
25
db/schema.rb
@ -12,47 +12,48 @@
|
|||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_05_29_081537) do
|
ActiveRecord::Schema.define(version: 2020_05_29_081537) do
|
||||||
|
|
||||||
create_table "favorite_courses", force: :cascade do |t|
|
create_table "favorite_courses", primary_key: ["id", "user_id"], force: :cascade do |t|
|
||||||
|
t.integer "id"
|
||||||
|
t.integer "user_id"
|
||||||
t.string "number", null: false
|
t.string "number", null: false
|
||||||
t.string "semester", null: false
|
t.string "semester", null: false
|
||||||
t.string "title", null: false
|
t.string "title", null: false
|
||||||
t.integer "user_id", null: false
|
|
||||||
t.string "personal_annotation"
|
t.string "personal_annotation"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
t.index ["number", "semester"], name: "index_favorite_courses_on_number_and_semester", unique: true
|
t.index ["user_id"], name: "index_favorite_courses_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "favorite_people", id: false, force: :cascade do |t|
|
create_table "favorite_people", primary_key: ["tiss_id", "user_id"], force: :cascade do |t|
|
||||||
t.integer "tiss_id", null: false
|
t.integer "tiss_id", null: false
|
||||||
t.integer "user_id", null: false
|
t.integer "user_id"
|
||||||
t.string "first_name"
|
t.string "first_name"
|
||||||
t.string "last_name"
|
t.string "last_name"
|
||||||
t.string "picture_uri"
|
t.string "picture_uri"
|
||||||
t.string "personal_annotation"
|
t.string "personal_annotation"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true
|
t.index ["user_id"], name: "index_favorite_people_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "favorite_projects", id: false, force: :cascade do |t|
|
create_table "favorite_projects", primary_key: ["id", "user_id"], force: :cascade do |t|
|
||||||
t.integer "id", null: false
|
t.integer "id", null: false
|
||||||
t.integer "user_id", null: false
|
t.integer "user_id"
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.string "personal_annotation"
|
t.string "personal_annotation"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
t.index ["id"], name: "index_favorite_projects_on_id", unique: true
|
t.index ["user_id"], name: "index_favorite_projects_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "favorite_theses", id: false, force: :cascade do |t|
|
create_table "favorite_theses", primary_key: ["id", "user_id"], force: :cascade do |t|
|
||||||
t.integer "id", null: false
|
t.integer "id", null: false
|
||||||
t.integer "user_id", null: false
|
t.integer "user_id"
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.string "personal_annotation"
|
t.string "personal_annotation"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
t.index ["id"], name: "index_favorite_theses_on_id", unique: true
|
t.index ["user_id"], name: "index_favorite_theses_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user