File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed
Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Kirschbaum \PowerJoins \Exceptions ;
4+
5+ use Exception ;
6+
7+ class SingleCallbackNotAllowed extends Exception
8+ {
9+ /** The error message */
10+ protected $ message = 'Single callback is not allowed here. ' ;
11+ }
Original file line number Diff line number Diff line change 1616use Illuminate \Database \Eloquent \SoftDeletingScope ;
1717use Illuminate \Database \MySqlConnection ;
1818use Illuminate \Support \Str ;
19+ use Kirschbaum \PowerJoins \Exceptions \SingleCallbackNotAllowed ;
1920use Kirschbaum \PowerJoins \PowerJoinClause ;
2021use Kirschbaum \PowerJoins \StaticCache ;
2122
@@ -129,6 +130,8 @@ protected function performJoinForEloquentPowerJoinsForBelongsToMany()
129130
130131 if (is_array ($ callback ) && isset ($ callback [$ this ->getTable ()])) {
131132 $ callback [$ this ->getTable ()]($ join );
133+ } elseif ($ callback && is_callable ($ callback )) {
134+ throw new SingleCallbackNotAllowed ();
132135 }
133136 });
134137
Original file line number Diff line number Diff line change 33namespace Kirschbaum \PowerJoins \Tests ;
44
55use Exception ;
6+ use Kirschbaum \PowerJoins \Exceptions \SingleCallbackNotAllowed ;
67use Kirschbaum \PowerJoins \PowerJoinClause ;
78use Kirschbaum \PowerJoins \Tests \Models \Category ;
89use Kirschbaum \PowerJoins \Tests \Models \Comment ;
@@ -271,6 +272,14 @@ public function test_join_belongs_to_many_with_callback()
271272 );
272273 }
273274
275+ /** @test */
276+ public function test_single_callback_in_belongs_to_many_should_throw_exception ()
277+ {
278+ $ this ->expectException (SingleCallbackNotAllowed::class);
279+
280+ User::query ()->joinRelationship ('groups ' , fn ($ join ) => $ join ->where ('groups.name ' , 'Test ' ));
281+ }
282+
274283 /** @test */
275284 public function test_it_doesnt_join_the_same_relationship_twice ()
276285 {
You can’t perform that action at this time.
0 commit comments