joinWhere()
Adds a conditional filter directly to a SQL JOIN
clause. Acts like a WHERE
statement on the joined table. You can combine multiple calls with joinOrWhere()
for more advanced filtering.
Signature:
public function joinWhere(string $joinTable, string $column, mixed $value = null, string $operator = '=', string $cond = 'AND'): self
Example: JOIN with AND Condition
// Get all orders from active users only
$db->join('test_users u', 'u.id = o.user_id', 'INNER');
$db->joinWhere('test_users u', 'u.status', 'active');
$db->get('test_orders o', null, 'o.*, u.email');
Equivalent SQL:
SELECT o.*, u.email
FROM test_orders o
INNER JOIN test_users u ON u.id = o.user_id AND u.status = 'active'
Example: JOIN with OR Condition
// Get all orders from users who are either active OR admin
$db->join('test_users u', 'u.id = o.user_id', 'INNER');
$db->joinWhere('test_users u', 'u.status', 'active');
$db->joinOrWhere('test_users u', 'u.type', 'admin');
$db->get('test_orders o', null, 'o.*, u.email');
Equivalent SQL:
SELECT o.*, u.email
FROM test_orders o
INNER JOIN test_users u ON u.id = o.user_id AND (u.status = 'active' OR u.type = 'admin')