I'm trying to filter results of a table based on two associated tables using a logical disjunction (OR).
For example I want to find all Products
filtering on Reviews
and Reviews.Users
.
where Reviews.Users.super
is ->eq(true)
OR
where Reviews.visibility
is ->eq('visibility', 'public')
AND Reviews.published
is ->isNotNull('published')
using two ->innerJoinWith
creates a conjunction.
this->Products->find()
->distinct()
->where(['Products.status' => 'current'])
->contain(['Reviews.Users'])
->innerJoinWith('Reviews', function($q) {
return $q
->where(['Reviews.visibility' => 'public'])
->andWhere(['Reviews.published IS NOT' => null]);
})
->innerJoinWith('Reviews.Users', function($q) {
return $q
->where(['Users.super' => true]);
})
->all();
when trying to use leftJoin
s as suggested by @ndm I get a
$this->Products->find()
->leftJoinWith('Reviews')
->leftJoinWith('Reviews.Users')
->where([
'OR' => [
'Reviews.Users.super' => true,
'Reviews.visibility' => 'public'
]
])
->andWhere([
'Reviews.published IS NOT' => null
])
Column not found: 1054 Unknown column 'Reviews.Users.super' in 'where clause'