JoinClause - viames/pair GitHub Wiki

Pair framework: JoinClause

Pair\Orm\JoinClause builds complex JOIN ... ON ... conditions for Query.

Constructor

$join = new \Pair\Orm\JoinClause('left', 'users u');

Main methods

Join predicates

  • on(string $first, string $operator, string $second, string $boolean = 'and')
  • orOn(string $first, string $operator, string $second)

Join where predicates

  • where(string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
  • orWhere(...)
  • whereIn(string $column, array $values, string $boolean = 'and', bool $not = false)
  • whereNotIn(...), orWhereIn(...), orWhereNotIn(...)
  • whereNull(string $column, string $boolean = 'and', bool $not = false)
  • whereNotNull(...), orWhereNull(...), orWhereNotNull(...)
  • whereRaw(string $sql, array $bindings = [], string $boolean = 'and')
  • orWhereRaw(...)

Introspection

  • getClauses(): array
  • getBindings(): array

Implementation example in Query

use Pair\Orm\Query;

$rows = Query::table('orders o')
    ->leftJoin('users u', function ($join) {
        $join->on('u.id', '=', 'o.user_id')
             ->where('u.active', 1)
             ->whereNotNull('u.email')
             ->orWhereIn('u.role', ['admin', 'manager']);
    })
    ->select('o.id', 'u.email')
    ->get();

This allows expressive join conditions without raw SQL for most cases.

See also: Query, QueryGrammar, Database.