From 780bf16034f29904e6c1ba15992664eb41dc4d85 Mon Sep 17 00:00:00 2001 From: Kyran Date: Sat, 25 Sep 2021 16:35:09 +1000 Subject: [PATCH 01/14] Fix issue with scope Fixes the issue "Column 'id' in where clause is ambiguous" when using additional scopes. --- src/Traits/TeamworkTeamTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/TeamworkTeamTrait.php b/src/Traits/TeamworkTeamTrait.php index 71f7fb9..11dcbab 100644 --- a/src/Traits/TeamworkTeamTrait.php +++ b/src/Traits/TeamworkTeamTrait.php @@ -49,6 +49,6 @@ public function owner() */ public function hasUser(Model $user) { - return $this->users()->where($user->getKeyName(), '=', $user->getKey())->first() ? true : false; + return $this->users()->where($model->getTable() . $user->getKeyName(), '=', $user->getKey())->first() ? true : false; } } From 82ad455109b52106c51f7209fd8716879968ec93 Mon Sep 17 00:00:00 2001 From: Kyran Date: Sat, 25 Sep 2021 16:45:54 +1000 Subject: [PATCH 02/14] Update TeamworkTeamTrait.php --- src/Traits/TeamworkTeamTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/TeamworkTeamTrait.php b/src/Traits/TeamworkTeamTrait.php index 11dcbab..28530aa 100644 --- a/src/Traits/TeamworkTeamTrait.php +++ b/src/Traits/TeamworkTeamTrait.php @@ -49,6 +49,6 @@ public function owner() */ public function hasUser(Model $user) { - return $this->users()->where($model->getTable() . $user->getKeyName(), '=', $user->getKey())->first() ? true : false; + return $this->users()->where($user->getTable() . $user->getKeyName(), '=', $user->getKey())->first() ? true : false; } } From e5c7a503e11fee124abbbb7a5abd718221baa7db Mon Sep 17 00:00:00 2001 From: Kyran Date: Sat, 25 Sep 2021 17:02:35 +1000 Subject: [PATCH 03/14] Update TeamworkTeamTrait.php --- src/Traits/TeamworkTeamTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/TeamworkTeamTrait.php b/src/Traits/TeamworkTeamTrait.php index 28530aa..242247c 100644 --- a/src/Traits/TeamworkTeamTrait.php +++ b/src/Traits/TeamworkTeamTrait.php @@ -49,6 +49,6 @@ public function owner() */ public function hasUser(Model $user) { - return $this->users()->where($user->getTable() . $user->getKeyName(), '=', $user->getKey())->first() ? true : false; + return $this->users()->where($user->getTable() . '.' . $user->getKeyName(), '=', $user->getKey())->first() ? true : false; } } From d530c1554d5e795e39005a20c2ab4f84ac356764 Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:11:14 +1000 Subject: [PATCH 04/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index a271f62..688a6ac 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -86,7 +86,7 @@ public function testHasUser() $stub->shouldReceive('where') ->once() - ->with('user_id', '=', 'key') + ->with('users.user_id', '=', 'key') ->andReturnSelf(); $stub->shouldReceive('users') From 4be07d802afc7cdd7521bc1a00c17e78c704903b Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:11:54 +1000 Subject: [PATCH 05/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index 688a6ac..f0f3fdd 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -110,7 +110,7 @@ public function testHasUserReturnsFalse() $stub->shouldReceive('where') ->once() - ->with('user_id', '=', 'key') + ->with('users.user_id', '=', 'key') ->andReturnSelf(); $stub->shouldReceive('users') From 5c4d45e31ea001293216c2d59d175f6bbc8f830c Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:21:15 +1000 Subject: [PATCH 06/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index f0f3fdd..4a25db2 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -75,18 +75,23 @@ public function testHasUser() { $stub = m::mock('\Mpociot\Teamwork\Tests\Feature\TestUserTeamTraitStub[users,first]'); - $user = m::mock('\Mpociot\Teamwork\Tests\Feature\TestUser[getKey]'); + $user = m::mock('\Mpociot\Teamwork\Tests\Feature\TestUser[getKey, getTable]'); + $user->shouldReceive('getKey') ->once() ->andReturn('key'); + $user->shouldReceive('getTable') + ->once() + ->andReturn('users'); + $stub->shouldReceive('first') ->once() ->andReturn(true); $stub->shouldReceive('where') ->once() - ->with('users.user_id', '=', 'key') + ->with('$this->user->getTable() . '.' . $this->user->getKeyName(), '=', $this->user->getKey()) ->andReturnSelf(); $stub->shouldReceive('users') @@ -99,18 +104,23 @@ public function testHasUserReturnsFalse() { $stub = m::mock('\Mpociot\Teamwork\Tests\Feature\TestUserTeamTraitStub[users,first]'); - $user = m::mock('\Mpociot\Teamwork\Tests\Feature\TestUser[getKey]'); + $user = m::mock('\Mpociot\Teamwork\Tests\Feature\TestUser[getKey, getTable]'); + $user->shouldReceive('getKey') ->once() ->andReturn('key'); + $user->shouldReceive('getTable') + ->once() + ->andReturn('users'); + $stub->shouldReceive('first') ->once() ->andReturn(false); $stub->shouldReceive('where') ->once() - ->with('users.user_id', '=', 'key') + ->with('$this->user->getTable() . '.' . $this->user->getKeyName(), '=', $this->user->getKey()) ->andReturnSelf(); $stub->shouldReceive('users') @@ -126,6 +136,11 @@ public function getKeyName() { return 'user_id'; } + + public function getTable() + { + return 'users'; + } } class TestUserTeamTraitStub extends \Illuminate\Database\Eloquent\Model From 9d0e53c0a9e9af33df0a228eefa2883a41883905 Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:22:21 +1000 Subject: [PATCH 07/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index 4a25db2..3e6e48f 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -91,7 +91,7 @@ public function testHasUser() $stub->shouldReceive('where') ->once() - ->with('$this->user->getTable() . '.' . $this->user->getKeyName(), '=', $this->user->getKey()) + ->with($this->user->getTable() . '.' . $this->user->getKeyName(), '=', $this->user->getKey()) ->andReturnSelf(); $stub->shouldReceive('users') From 186675fef51e75cad15bfaf0e4166cc5b2f73dad Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:23:10 +1000 Subject: [PATCH 08/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index 3e6e48f..b003858 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -120,7 +120,7 @@ public function testHasUserReturnsFalse() $stub->shouldReceive('where') ->once() - ->with('$this->user->getTable() . '.' . $this->user->getKeyName(), '=', $this->user->getKey()) + ->with($this->user->getTable() . '.' . $this->user->getKeyName(), '=', $this->user->getKey()) ->andReturnSelf(); $stub->shouldReceive('users') From e5fd19a23457365fc2f8467642b926c4c0030153 Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:27:30 +1000 Subject: [PATCH 09/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index b003858..947f440 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -146,4 +146,9 @@ public function getTable() class TestUserTeamTraitStub extends \Illuminate\Database\Eloquent\Model { use TeamworkTeamTrait; + + public function getTable() + { + return 'teams_users'; + } } From abc381aa7e0e3f2a67274bb5e944202689c46387 Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:30:29 +1000 Subject: [PATCH 10/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index 947f440..926c242 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -91,7 +91,7 @@ public function testHasUser() $stub->shouldReceive('where') ->once() - ->with($this->user->getTable() . '.' . $this->user->getKeyName(), '=', $this->user->getKey()) + ->with('users.user_id, '=', $this->user->getKey()) ->andReturnSelf(); $stub->shouldReceive('users') @@ -120,7 +120,7 @@ public function testHasUserReturnsFalse() $stub->shouldReceive('where') ->once() - ->with($this->user->getTable() . '.' . $this->user->getKeyName(), '=', $this->user->getKey()) + ->with('users.user_id, '=', $this->user->getKey()) ->andReturnSelf(); $stub->shouldReceive('users') @@ -146,9 +146,4 @@ public function getTable() class TestUserTeamTraitStub extends \Illuminate\Database\Eloquent\Model { use TeamworkTeamTrait; - - public function getTable() - { - return 'teams_users'; - } } From d4aa6cb79debcaf429f417f855fa4c1433d114ad Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:32:29 +1000 Subject: [PATCH 11/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index 926c242..47a1902 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -91,7 +91,7 @@ public function testHasUser() $stub->shouldReceive('where') ->once() - ->with('users.user_id, '=', $this->user->getKey()) + ->with('users.user_id', '=', $this->user->getKey()) ->andReturnSelf(); $stub->shouldReceive('users') @@ -120,7 +120,7 @@ public function testHasUserReturnsFalse() $stub->shouldReceive('where') ->once() - ->with('users.user_id, '=', $this->user->getKey()) + ->with('users.user_id', '=', $this->user->getKey()) ->andReturnSelf(); $stub->shouldReceive('users') From 3b0cb8c6fe3349960c1bbf4be0c23f7042618010 Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:33:52 +1000 Subject: [PATCH 12/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index 47a1902..c089f56 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -141,6 +141,11 @@ public function getTable() { return 'users'; } + + public function getKey() + { + return 'id'; + } } class TestUserTeamTraitStub extends \Illuminate\Database\Eloquent\Model From 61e3bb2cab3190ba5e53d633f0107512bd73b3aa Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:35:47 +1000 Subject: [PATCH 13/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index c089f56..6f605cb 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -144,7 +144,7 @@ public function getTable() public function getKey() { - return 'id'; + return 'key'; } } From 1cf75426146f492baafeb0c3213a6507a41037d4 Mon Sep 17 00:00:00 2001 From: Kyran Date: Mon, 11 Sep 2023 20:36:38 +1000 Subject: [PATCH 14/14] Update TeamworkTeamTraitTest.php --- tests/Feature/TeamworkTeamTraitTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/TeamworkTeamTraitTest.php b/tests/Feature/TeamworkTeamTraitTest.php index 6f605cb..5dc73d8 100644 --- a/tests/Feature/TeamworkTeamTraitTest.php +++ b/tests/Feature/TeamworkTeamTraitTest.php @@ -91,7 +91,7 @@ public function testHasUser() $stub->shouldReceive('where') ->once() - ->with('users.user_id', '=', $this->user->getKey()) + ->with('users.user_id', '=', 'key') ->andReturnSelf(); $stub->shouldReceive('users') @@ -120,7 +120,7 @@ public function testHasUserReturnsFalse() $stub->shouldReceive('where') ->once() - ->with('users.user_id', '=', $this->user->getKey()) + ->with('users.user_id', '=', 'key') ->andReturnSelf(); $stub->shouldReceive('users')