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.

{} It's a method of the class: OrdersTableMetaQuery{}

No Hooks.

Return

String. A table alias for use in an SQL JOIN clause.

Usage

// private - for code of main (parent) class only
$result = $this->find_or_create_table_alias_for_clause( $clause, $parent_query ): string;
$clause(array) (required)
An atomic meta_query clause.
$parent_query(array) (required)
The parent query this clause is in.

Code of OrdersTableMetaQuery::find_or_create_table_alias_for_clause() WC 7.1.0

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;
}