は私が 外部キーレール、追加方法?
class User
has_many :questions, trough: votes
has_many :questions #(as the author)
has_many :votes
end
が作成したときFOREIGN_KEYを追加するのを忘れなければならないのよりシンプルにするために、今私は、特定の(has_manyの経由)関連
schema.rb
に追加する方法がわかりませんenable_extension "plpgsql"
create_table "answers", force: :cascade do |t|
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "question_id"
t.integer "user_id"
t.boolean "best", default: false
end
add_index "answers", ["question_id"], name: "index_answers_on_question_id", using: :btree
add_index "answers", ["user_id"], name: "index_answers_on_user_id", using: :btree
create_table "attachments", force: :cascade do |t|
t.string "file"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "attachable_id"
t.string "attachable_type"
end
add_index "attachments", ["attachable_id", "attachable_type"], name: "index_attachments_on_attachable_id_and_attachable_type", using: :btree
create_table "questions", force: :cascade do |t|
t.string "title"
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end
add_index "questions", ["title"], name: "index_questions_on_title", using: :btree
add_index "questions", ["user_id"], name: "index_questions_on_user_id", using: :btree
create_table "users", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["name"], name: "index_users_on_name", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
create_table "votes", force: :cascade do |t|
t.integer "votable_id"
t.string "votable_type"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "votes", ["user_id", "votable_id"], name: "index_votes_on_user_id_and_votable_id", unique: true, using: :btree
add_foreign_key "answers", "questions", on_delete: :cascade
add_foreign_key "questions", "users", on_delete: :cascade
end
あなたは 'デシベル/ schema.rb'を投稿することができますか? – siegy22
他のモデルではuser_idを意味します –
RaVeN 'code'create_table "votes"、force::cascade do | t | t.integer "votable_id" t.string "votable_type" t.integer "user_id" t.datetime "created_at"、null:false t。datetime "updated_at"、null:false end –