Add position attribute to relation between exercise collection and exercises

This commit is contained in:
Maximilian Grundke
2018-07-03 15:23:00 +02:00
parent 0395d5b038
commit b68b3bc2b0
5 changed files with 31 additions and 11 deletions

View File

@ -14,7 +14,8 @@ class Exercise < ActiveRecord::Base
has_and_belongs_to_many :proxy_exercises has_and_belongs_to_many :proxy_exercises
has_many :user_proxy_exercise_exercises has_many :user_proxy_exercise_exercises
has_and_belongs_to_many :exercise_collections has_many :exercise_collection_items
has_many :exercise_collections, through: :exercise_collection_items
has_many :user_exercise_interventions has_many :user_exercise_interventions
has_many :interventions, through: :user_exercise_interventions has_many :interventions, through: :user_exercise_interventions
has_many :exercise_tags has_many :exercise_tags

View File

@ -1,7 +1,8 @@
class ExerciseCollection < ActiveRecord::Base class ExerciseCollection < ActiveRecord::Base
include TimeHelper include TimeHelper
has_and_belongs_to_many :exercises has_many :exercise_collection_items
has_many :exercises, through: :exercise_collection_items
belongs_to :user, polymorphic: true belongs_to :user, polymorphic: true
def exercise_working_times def exercise_working_times

View File

@ -0,0 +1,4 @@
class ExerciseCollectionItem < ActiveRecord::Base
belongs_to :exercise_collection
belongs_to :exercise
end

View File

@ -0,0 +1,13 @@
class CreateExerciseCollectionItems < ActiveRecord::Migration
def up
rename_table :exercise_collections_exercises, :exercise_collection_items
add_column :exercise_collection_items, :position, :integer, default: 0, null: false
add_column :exercise_collection_items, :id, :primary_key
end
def down
remove_column :exercise_collection_items, :position
remove_column :exercise_collection_items, :id
rename_table :exercise_collection_items, :exercise_collections_exercises
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180515110030) do ActiveRecord::Schema.define(version: 20180703125302) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -114,6 +114,15 @@ ActiveRecord::Schema.define(version: 20180515110030) do
t.boolean "network_enabled" t.boolean "network_enabled"
end end
create_table "exercise_collection_items", force: :cascade do |t|
t.integer "exercise_collection_id"
t.integer "exercise_id"
t.integer "position", default: 0, null: false
end
add_index "exercise_collection_items", ["exercise_collection_id"], name: "index_exercise_collection_items_on_exercise_collection_id", using: :btree
add_index "exercise_collection_items", ["exercise_id"], name: "index_exercise_collection_items_on_exercise_id", using: :btree
create_table "exercise_collections", force: :cascade do |t| create_table "exercise_collections", force: :cascade do |t|
t.string "name" t.string "name"
t.datetime "created_at" t.datetime "created_at"
@ -125,14 +134,6 @@ ActiveRecord::Schema.define(version: 20180515110030) do
add_index "exercise_collections", ["user_type", "user_id"], name: "index_exercise_collections_on_user_type_and_user_id", using: :btree add_index "exercise_collections", ["user_type", "user_id"], name: "index_exercise_collections_on_user_type_and_user_id", using: :btree
create_table "exercise_collections_exercises", id: false, force: :cascade do |t|
t.integer "exercise_collection_id"
t.integer "exercise_id"
end
add_index "exercise_collections_exercises", ["exercise_collection_id"], name: "index_exercise_collections_exercises_on_exercise_collection_id", using: :btree
add_index "exercise_collections_exercises", ["exercise_id"], name: "index_exercise_collections_exercises_on_exercise_id", using: :btree
create_table "exercise_tags", force: :cascade do |t| create_table "exercise_tags", force: :cascade do |t|
t.integer "exercise_id" t.integer "exercise_id"
t.integer "tag_id" t.integer "tag_id"