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:
Pfingstfrosch
2020-06-05 00:35:04 +02:00
parent 1e87036094
commit ca38d7260d
12 changed files with 38 additions and 36 deletions
@@ -1,15 +1,13 @@
class CreateFavoritePeople < ActiveRecord::Migration[6.0]
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 :user_id, null: false
t.belongs_to :user
t.string :first_name
t.string :last_name
t.string :picture_uri
t.string :personal_annotation
t.timestamps
end
add_index :favorite_people, :tiss_id, unique: true
end
end
@@ -1,14 +1,14 @@
class CreateFavoriteCourses < ActiveRecord::Migration[6.0]
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 :semester, null: false
t.string :title, null: false
t.integer :user_id, null: false
t.string :personal_annotation
t.timestamps
end
add_index :favorite_courses, [:number, :semester], unique: true
end
end
@@ -1,13 +1,12 @@
class CreateFavoriteTheses < ActiveRecord::Migration[6.0]
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 :user_id, null: false
t.belongs_to :user
t.string :title
t.string :personal_annotation
t.timestamps
end
add_index :favorite_theses, :id, unique: true
end
end
@@ -1,13 +1,12 @@
class CreateFavoriteProjects < ActiveRecord::Migration[6.0]
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 :user_id, null: false
t.belongs_to :user
t.string :title
t.string :personal_annotation
t.timestamps
end
add_index :favorite_projects, :id, unique: true
end
end