@@ -1105,6 +1105,23 @@ public function testForPageBeforeIdCorrectlyPaginates()
1105
1105
$ this ->assertEquals (1 , $ results ->first ()->id );
1106
1106
}
1107
1107
1108
+ public function testForPageBeforeIdCorrectlyNestExistingWhereClauses ()
1109
+ {
1110
+ EloquentTestUser::create (['id ' => 1 , 'email ' => 'taylorotwell@gmail.com ' ]);
1111
+ EloquentTestUser::create (['id ' => 2 , 'email ' => 'abigailotwell@gmail.com ' ]);
1112
+ EloquentTestUser::create (['id ' => 3 , 'email ' => 'jamesotwell@gmail.com ' ]);
1113
+ EloquentTestUser::create (['id ' => 4 , 'email ' => 'victoriaotwell@gmail.com ' ]);
1114
+
1115
+ // Without nesting the query, it would generate something along the lines
1116
+ // of `WHERE id = 4 OR (id = 1 AND id < 3)`, which would return 2 rows,
1117
+ // When correctly nested, it generates a proper where clause, such as:
1118
+ // `WHERE (id = 4 OR id = 1) AND id < 3`, which returns a single row
1119
+ $ results = EloquentTestUser::where ('id ' , 4 )->orWhere ('id ' , 1 )->forPageBeforeId (15 , 3 );
1120
+ $ this ->assertInstanceOf (Builder::class, $ results );
1121
+ $ this ->assertEquals (1 , $ results ->count ());
1122
+ $ this ->assertEquals (1 , $ results ->first ()->id );
1123
+ }
1124
+
1108
1125
public function testForPageAfterIdCorrectlyPaginates ()
1109
1126
{
1110
1127
EloquentTestUser::create (['id ' => 1 , 'email ' => 'taylorotwell@gmail.com ' ]);
@@ -1119,6 +1136,20 @@ public function testForPageAfterIdCorrectlyPaginates()
1119
1136
$ this ->assertEquals (2 , $ results ->first ()->id );
1120
1137
}
1121
1138
1139
+ public function testForPageAfterIdCorrectlyNestExistingWhereClauses ()
1140
+ {
1141
+ EloquentTestUser::create (['id ' => 1 , 'email ' => 'taylorotwell@gmail.com ' ]);
1142
+ EloquentTestUser::create (['id ' => 2 , 'email ' => 'abigailotwell@gmail.com ' ]);
1143
+
1144
+ // Without nesting the query, it would generate something along the lines
1145
+ // of `WHERE id = 1 OR (id = 2 AND id > 1)`, which would always return 1.
1146
+ // When correctly nested, it generates a proper where clause, such as:
1147
+ // `WHERE (id = 1 OR id = 2) AND id > 1`
1148
+ $ results = EloquentTestUser::where ('id ' , 1 )->orWhere ('id ' , 2 )->forPageAfterId (15 , 1 );
1149
+ $ this ->assertInstanceOf (Builder::class, $ results );
1150
+ $ this ->assertEquals (2 , $ results ->first ()->id );
1151
+ }
1152
+
1122
1153
public function testMorphToRelationsAcrossDatabaseConnections ()
1123
1154
{
1124
1155
$ item = null ;
0 commit comments