Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableMetaQuery::find_or_create_table_alias_for_clause()privateWC 1.0

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

{} Это метод класса: OrdersTableMetaQuery{}

Хуков нет.

Возвращает

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

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

// private - только в коде основоного (родительского) класса
$result = $this->find_or_create_table_alias_for_clause( $clause, $parent_query ): string;
$clause(массив) (обязательный)
An atomic meta_query clause.
$parent_query(массив) (обязательный)
The parent query this clause is in.

Код OrdersTableMetaQuery::find_or_create_table_alias_for_clause() WC 6.9.4

private function find_or_create_table_alias_for_clause( array $clause, array $parent_query ): string {
	if ( ! empty( $clause['alias'] ) ) {
		return $clause['alias'];
	}

	$alias    = false;
	$siblings = array_filter(
		$parent_query,
		array( __CLASS__, 'is_atomic' )
	);

	foreach ( $siblings as $sibling ) {
		if ( empty( $sibling['alias'] ) ) {
			continue;
		}

		if ( $this->is_operator_compatible_with_shared_join( $clause, $sibling, $parent_query['relation'] ?? 'AND' ) ) {
			$alias = $sibling['alias'];
			break;
		}
	}

	if ( ! $alias ) {
		$alias                 = self::ALIAS_PREFIX . count( $this->table_aliases );
		$this->join[]          = $this->generate_join_for_clause( $clause, $alias );
		$this->table_aliases[] = $alias;
	}

	return $alias;
}