lithium\data\source\Database::join()

public method

Set a query's join according a Relationship.

Parameters

  • object $context

    A Query instance

  • object $rel

    A Relationship instance

  • string $fromAlias

    Set a specific alias for the 'from' Model.

  • string $toAlias

    Set a specific alias for 'to' Model.

  • mixed $constraints

    If $constraints is an array, it will be merged to defaults constraints. If $constraints is an object, defaults won't be merged.

Source

	public function join($context, $rel, $fromAlias = null, $toAlias = null, $constraints = []) {
		$model = $rel->to();

		if ($fromAlias === null) {
			$fromAlias = $context->alias();
		}
		if ($toAlias === null) {
			$toAlias = $context->alias(null, $rel->name());
		}
		if (!is_object($constraints)) {
			$constraints = $this->on($rel, $fromAlias, $toAlias, $constraints);
		} else {
			$constraints = (array) $constraints;
		}

		$context->joins($toAlias, compact('constraints', 'model') + [
			'mode' => 'LEFT',
			'alias' => $toAlias
		]);
	}