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

public method

Build the ON constraints from a Relationship instance

Parameters

  • object $rel

    A Relationship instance

  • string $fromAlias

    Set a specific alias for the 'from' Model.

  • string $toAlias

    Set a specific alias for 'to' Model.

  • array $constraints

    Array of additionnal $constraints.

Returns

array

A constraints array.

Source

	public function on($rel, $aliasFrom = null, $aliasTo = null, $constraints = []) {
		$model = $rel->from();

		$aliasFrom = $aliasFrom ?: $model::meta('name');
		$aliasTo = $aliasTo ?: $rel->name();

		$keyConstraints = [];
		foreach ($rel->key() as $from => $to) {
			$keyConstraints["{$aliasFrom}.{$from}"] = "{$aliasTo}.{$to}";
		}

		$mapAlias = [$model::meta('name') => $aliasFrom, $rel->name() => $aliasTo];

		$relConstraints = $this->_on((array) $rel->constraints(), $aliasFrom, $aliasTo, $mapAlias);
		$constraints = $this->_on($constraints, $aliasFrom, $aliasTo, []);

		return $constraints + $relConstraints + $keyConstraints;
	}