-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to cover morphTo with hybrid MongoDB and SQL
- Loading branch information
Showing
7 changed files
with
147 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MongoDB\Laravel\Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model as EloquentModel; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Schema\SQLiteBuilder; | ||
use Illuminate\Support\Facades\Schema; | ||
use MongoDB\Laravel\Eloquent\HybridRelations; | ||
use MongoDB\Laravel\Relations\MorphTo; | ||
|
||
use function assert; | ||
|
||
class SqlPhoto extends EloquentModel | ||
{ | ||
use HybridRelations; | ||
|
||
protected $connection = 'sqlite'; | ||
protected $table = 'photo'; | ||
protected $fillable = ['url']; | ||
|
||
public function hasImage(): MorphTo | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
/** | ||
* Check if we need to run the schema. | ||
*/ | ||
public static function executeSchema() | ||
{ | ||
$schema = Schema::connection('sqlite'); | ||
assert($schema instanceof SQLiteBuilder); | ||
|
||
$schema->dropIfExists('photo'); | ||
$schema->create('photo', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('url'); | ||
$table->string('has_image_id')->nullable(); | ||
$table->string('has_image_type')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters