Skip to content

Commit

Permalink
use morphs in migration
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Sep 2, 2015
1 parent 6395021 commit 43ba64a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All Notable changes to `laravel-medialibrary` will be documented in this file

##3.2.3
- Add index to morphable fields in migration which could improve performance.
- Remove unnecessary query when adding a file

##3.2.2
- Fixes tests

Expand Down
4 changes: 1 addition & 3 deletions resources/migrations/create_media_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class CreateMediaTable extends Migration
{
Schema::create('media', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('model_id')->nullable();
$table->string('model_type')->nullable();
$table->index(['model_id', 'model_type']);
$table->morphs('model');
$table->string('collection_name');
$table->string('name');
$table->string('file_name');
Expand Down
3 changes: 1 addition & 2 deletions src/FileAdder/FileAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ public function toCollectionOnDisk($collectionName = 'default', $diskName = '')
$media->custom_properties = $this->customProperties;
$media->manipulations = [];

$media->save();

$this->subject->media()->save($media);

$this->fileSystem->add($this->pathToFile, $media, $this->fileName);

if (!$this->preserveOriginal) {
Expand Down

0 comments on commit 43ba64a

Please sign in to comment.