-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.7] hyphen-case the Syslog program name (#25784)
* Support MorphTo eager loading with selected columns (#25662) * version * hyphen-case the Syslog program name Follow existing program name conventions to have more readable logs. * Use Str directly
- Loading branch information
1 parent
d800c60
commit 58ef321
Showing
3 changed files
with
99 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Database\EloquentMorphToSelectTest; | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Tests\Integration\Database\DatabaseTestCase; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class EloquentMorphToSelectTest extends DatabaseTestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create('posts', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::create('comments', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('commentable_type'); | ||
$table->integer('commentable_id'); | ||
}); | ||
|
||
$post = Post::create(); | ||
(new Comment)->commentable()->associate($post)->save(); | ||
} | ||
|
||
public function test_select() | ||
{ | ||
$comments = Comment::with('commentable:id')->get(); | ||
|
||
$this->assertEquals(['id' => 1], $comments[0]->commentable->getAttributes()); | ||
} | ||
|
||
public function test_select_raw() | ||
{ | ||
$comments = Comment::with(['commentable' => function ($query) { | ||
$query->selectRaw('id'); | ||
}])->get(); | ||
|
||
$this->assertEquals(['id' => 1], $comments[0]->commentable->getAttributes()); | ||
} | ||
|
||
public function test_select_sub() | ||
{ | ||
$comments = Comment::with(['commentable' => function ($query) { | ||
$query->selectSub(function ($query) { | ||
$query->select('id'); | ||
}, 'id'); | ||
}])->get(); | ||
|
||
$this->assertEquals(['id' => 1], $comments[0]->commentable->getAttributes()); | ||
} | ||
|
||
public function test_add_select() | ||
{ | ||
$comments = Comment::with(['commentable' => function ($query) { | ||
$query->addSelect('id'); | ||
}])->get(); | ||
|
||
$this->assertEquals(['id' => 1], $comments[0]->commentable->getAttributes()); | ||
} | ||
|
||
public function test_lazy_loading() | ||
{ | ||
$comment = Comment::first(); | ||
$post = $comment->commentable()->select('id')->first(); | ||
|
||
$this->assertEquals(['id' => 1], $post->getAttributes()); | ||
} | ||
} | ||
|
||
class Comment extends Model | ||
{ | ||
public $timestamps = false; | ||
|
||
public function commentable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} | ||
|
||
class Post extends Model | ||
{ | ||
} |