@@ -49,6 +49,18 @@ protected function getFloatPrecision(float $value): string
4949 return sprintf ('%. ' . $ this ->floatPrecision . 'F ' , $ value );
5050 }
5151
52+ /**
53+ * Build conditions threading `$name` to per-query builders so adapter
54+ * overrides (SQLite FTS5 routing) can resolve auxiliary tables.
55+ *
56+ * @param array<Query> $queries
57+ * @param array<string,mixed> $binds
58+ */
59+ protected function getSQLConditionsForCollection (string $ name , array $ queries , array &$ binds , string $ separator = 'AND ' ): string
60+ {
61+ return $ this ->getSQLConditions ($ queries , $ binds , $ separator , $ name );
62+ }
63+
5264 /**
5365 * Constructor.
5466 *
@@ -2312,19 +2324,21 @@ public function getMaxUIDLength(): int
23122324 /**
23132325 * @param Query $query
23142326 * @param array<string, mixed> $binds
2327+ * @param ?string $forCollection Filtered collection id (for FTS5 routing).
23152328 * @return string
23162329 * @throws Exception
23172330 */
2318- abstract protected function getSQLCondition (Query $ query , array &$ binds ): string ;
2331+ abstract protected function getSQLCondition (Query $ query , array &$ binds, ? string $ forCollection = null ): string ;
23192332
23202333 /**
23212334 * @param array<Query> $queries
23222335 * @param array<string, mixed> $binds
23232336 * @param string $separator
2337+ * @param ?string $forCollection See {@see getSQLCondition}.
23242338 * @return string
23252339 * @throws Exception
23262340 */
2327- public function getSQLConditions (array $ queries , array &$ binds , string $ separator = 'AND ' ): string
2341+ public function getSQLConditions (array $ queries , array &$ binds , string $ separator = 'AND ' , ? string $ forCollection = null ): string
23282342 {
23292343 $ conditions = [];
23302344 foreach ($ queries as $ query ) {
@@ -2333,9 +2347,9 @@ public function getSQLConditions(array $queries, array &$binds, string $separato
23332347 }
23342348
23352349 if ($ query ->isNested ()) {
2336- $ conditions [] = $ this ->getSQLConditions ($ query ->getValues (), $ binds , $ query ->getMethod ());
2350+ $ conditions [] = $ this ->getSQLConditions ($ query ->getValues (), $ binds , $ query ->getMethod (), $ forCollection );
23372351 } else {
2338- $ conditions [] = $ this ->getSQLCondition ($ query , $ binds );
2352+ $ conditions [] = $ this ->getSQLCondition ($ query , $ binds, $ forCollection );
23392353 }
23402354 }
23412355
@@ -3155,7 +3169,7 @@ public function find(Document $collection, array $queries = [], ?int $limit = 25
31553169 $ where [] = '( ' . implode (' OR ' , $ cursorWhere ) . ') ' ;
31563170 }
31573171
3158- $ conditions = $ this ->getSQLConditions ( $ queries , $ binds );
3172+ $ conditions = $ this ->getSQLConditionsForCollection ( $ name , $ queries , $ binds );
31593173 if (!empty ($ conditions )) {
31603174 $ where [] = $ conditions ;
31613175 }
@@ -3299,7 +3313,7 @@ public function count(Document $collection, array $queries = [], ?int $max = nul
32993313 }
33003314 }
33013315
3302- $ conditions = $ this ->getSQLConditions ( $ otherQueries , $ binds );
3316+ $ conditions = $ this ->getSQLConditionsForCollection ( $ name , $ otherQueries , $ binds );
33033317 if (!empty ($ conditions )) {
33043318 $ where [] = $ conditions ;
33053319 }
@@ -3385,7 +3399,7 @@ public function sum(Document $collection, string $attribute, array $queries = []
33853399 }
33863400 }
33873401
3388- $ conditions = $ this ->getSQLConditions ( $ otherQueries , $ binds );
3402+ $ conditions = $ this ->getSQLConditionsForCollection ( $ name , $ otherQueries , $ binds );
33893403 if (!empty ($ conditions )) {
33903404 $ where [] = $ conditions ;
33913405 }
0 commit comments