Matching with multiple where clauses

Hi,

I have a query and want to use multiple matches I have done the following and when it uses one attribute it works, but when I use multiple attributes it returns empty array, does anyone have an idea how to solve this?

I am using separate table with attributes, because I want to use attributesets for different type of products…

if($this->request->query(‘Color’)){
$match[] = [‘ProductsAttributes.eav IN’ => $this->request->query(‘Color’),‘ProductsAttributes.attribute_id’ => ‘20’];
}
if($this->request->query(‘Brand’)){
$match[] = [‘ProductsAttributes.eav IN’ => $this->request->query(‘Brand’),‘ProductsAttributes.attribute_id’ => ‘22’];
}

	if (isset($match)){
	   $query = $this->Products
	       ->find('search', ['search' => $this->request->query])
	       ->contain(['Categories'])
	       ->matching('Attributes', function ($query) use ($match) {
	           return $query
	           ->where($match);
	           })
	       ->where($where);
	}else{
	    $query = $this->Products
	       ->find('search', ['search' => $this->request->query])
	       ->contain(['Categories'])
	       ->where($where);
	}

Actually the array would automaticly use AND condition by default.

$query = $this->Products
    	->find('search', ['search' => $this->request->query])
    	->contain(['Categories','ProductPromotions'])
    	->where($where);
    	
    	if($this->request->query('Color')){
    	    $color = $this->request->query('Color');
    	    $query->matching('Attributes', function ($query) use ($color) {
    	        return $query
    	           ->where(['AND' => ['ProductsAttributes.eav IN' => $color,'ProductsAttributes.attribute_id' => '20']]);
    	    });
    	}
    	if($this->request->query('Brand')){
    	    $brand = $this->request->query('Brand');
    	    $query->matching('Attributes', function ($query) use ($brand) {
    	        return $query
    	        ->where(['AND' => ['ProductsAttributes.eav IN' => $brand,'ProductsAttributes.attribute_id' => '22']]);
    	    });
    	}

I change it to this… When I select the color it works, when I select the brand it works. When I select both no results…

I think is the problem that I creates only one join, and that it should do two separate ones? Because you are matching the same fields with different value to match it???

Maybe you have run into this: