From 96d38afe75297883bedf66b60106dc84866758a5 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Fri, 8 Mar 2019 07:42:24 +0800 Subject: [PATCH] Add pic relation on issue model --- app/Entities/Projects/Issue.php | 5 +++++ tests/Unit/Models/IssueTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/Entities/Projects/Issue.php b/app/Entities/Projects/Issue.php index 025a4a0..a3c6ef4 100644 --- a/app/Entities/Projects/Issue.php +++ b/app/Entities/Projects/Issue.php @@ -15,6 +15,11 @@ class Issue extends Model return $this->belongsTo(Project::class); } + public function pic() + { + return $this->belongsTo(User::class); + } + public function creator() { return $this->belongsTo(User::class); diff --git a/tests/Unit/Models/IssueTest.php b/tests/Unit/Models/IssueTest.php index cb0fcb7..f3f4e37 100644 --- a/tests/Unit/Models/IssueTest.php +++ b/tests/Unit/Models/IssueTest.php @@ -22,6 +22,16 @@ class IssueTest extends TestCase } /** @test */ + public function an_issue_has_belongs_to_pic_relation() + { + $pic = $this->createUser('worker'); + $issue = factory(Issue::class)->make(['pic_id' => $pic->id]); + + $this->assertInstanceOf(User::class, $issue->pic); + $this->assertEquals($issue->pic_id, $issue->pic->id); + } + + /** @test */ public function an_issue_has_belongs_to_creator_relation() { $issue = factory(Issue::class)->make();