1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add a foreign-key constraint to the attachments table for blobs

This commit is contained in:
George Claghorn 2018-07-19 20:43:33 -04:00
parent 3f53296f18
commit 2ae3a29508
3 changed files with 3 additions and 2 deletions

View file

@ -20,6 +20,7 @@ class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
t.datetime :created_at, null: false t.datetime :created_at, null: false
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end end
end end
end end

View file

@ -10,7 +10,7 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
@user = User.create!(name: "Josh") @user = User.create!(name: "Josh")
end end
teardown { ActiveStorage::Blob.all.each(&:purge) } teardown { ActiveStorage::Blob.all.each(&:delete) }
test "attaching existing blobs to an existing record" do test "attaching existing blobs to an existing record" do
@user.highlights.attach create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") @user.highlights.attach create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg")

View file

@ -10,7 +10,7 @@ class ActiveStorage::OneAttachedTest < ActiveSupport::TestCase
@user = User.create!(name: "Josh") @user = User.create!(name: "Josh")
end end
teardown { ActiveStorage::Blob.all.each(&:purge) } teardown { ActiveStorage::Blob.all.each(&:delete) }
test "attaching an existing blob to an existing record" do test "attaching an existing blob to an existing record" do
@user.avatar.attach create_blob(filename: "funky.jpg") @user.avatar.attach create_blob(filename: "funky.jpg")