Yoast\WP\Lib

ORM::add_join_source()protectedYoast 1.0

Add a JOIN source to the query. Internal method.

The join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN.

The table should be the name of the table to join to.

The constraint may be either a string or an array with three elements. If it is a string, it will be compiled into the query as-is, with no escaping. The recommended way to supply the constraint is as an array with three elements:

first_column, operator, second_column

Example: array('user.id', '=', 'profile.user_id')

will compile to

ON user.id = profile.user_id

The final (optional) argument specifies an alias for the joined table.

Метод класса: ORM{}

Хуков нет.

Возвращает

ORM.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->add_join_source( $join_operator, $table, $constraint, $table_alias );
$join_operator(строка) (обязательный)
The join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN.
$table(строка) (обязательный)
The table should be the name of the table to join to.
$constraint(строка) (обязательный)
The constraint.
$table_alias(строка|null)
The alias for the joined table.
По умолчанию: null

Код ORM::add_join_source() Yoast 24.0

protected function add_join_source( $join_operator, $table, $constraint, $table_alias = null ) {
	$join_operator = \trim( "{$join_operator} JOIN" );
	$table         = $this->quote_identifier( $table );
	// Add table alias if present.
	if ( ! \is_null( $table_alias ) ) {
		$table_alias = $this->quote_identifier( $table_alias );
		$table      .= " {$table_alias}";
	}
	// Build the constraint.
	if ( \is_array( $constraint ) ) {
		list( $first_column, $operator, $second_column ) = $constraint;

		$first_column  = $this->quote_identifier( $first_column );
		$second_column = $this->quote_identifier( $second_column );
		$constraint    = "{$first_column} {$operator} {$second_column}";
	}
	$this->join_sources[] = "{$join_operator} {$table} ON {$constraint}";

	return $this;
}