I have a table structure like following:
Brands => BrandUser <= Users
I need to get brands which have corresponding record in the BrandUser table and the ones which don't have corresponding record in BrandUser table...
I have tried the following query:
public function getUserBrands($userId) {
$select = new Select();
$select->from(array('bu' => $this->table));
$select->join(array('b' => 'brands'), 'bu.brandId = b.id', array('id','name'));
$select->join(array('u' => 'users'), 'u.id = bu.userId', array('id','username'),Select::JOIN_LEFT);
$where = new Where();
$where->equalTo("bu.userId",$userId);
$select->where($where);
return $this->branduserTable->selectWith($select)->toArray();
}
But I only get users which HAVE corresponding record in the BrandUser table... I need to get the rest of the brands which don't have the corresponding value in BrandUser... How can I do this??