Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableFieldQuery::find_or_create_table_alias_for_clause()privateWC 1.0

Finds a common table alias that the field_query clause can use, or creates one.

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

Хуков нет.

Возвращает

Строку. A table alias for use in an SQL JOIN clause.

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

// private - только в коде основоного (родительского) класса
$result = $this->find_or_create_table_alias_for_clause( $q );
$q(массив) (обязательный)
An atomic field_query clause.

Код OrdersTableFieldQuery::find_or_create_table_alias_for_clause() WC 8.7.0

private function find_or_create_table_alias_for_clause( $q ) {
	global $wpdb;

	if ( ! empty( $q['alias'] ) ) {
		return $q['alias'];
	}

	if ( empty( $q['table'] ) || empty( $q['column'] ) ) {
		throw new \Exception( __( 'Missing table info for query arg.', 'woocommerce' ) );
	}

	$join = '';

	if ( isset( $q['mapping_id'] ) ) {
		// Re-use JOINs and aliases from OrdersTableQuery for core tables.
		$alias = $this->query->get_core_mapping_alias( $q['mapping_id'] );
		$join  = $this->query->get_core_mapping_join( $q['mapping_id'] );
	} else {
		$alias = $q['table'];
		$join  = '';
	}

	if ( in_array( $alias, $this->table_aliases, true ) ) {
		return $alias;
	}

	$this->table_aliases[] = $alias;

	if ( $join ) {
		$this->join[ $alias ] = $join;
	}

	return $alias;
}