I need to set conditions to fields of left joined table.
So I need to know:
Is this table has been left joined?
If so, what alias of leftjoined table to use to add new condition.
Here current code example:
class PStudentFormFilter extends BasePStudentFormFilter
{
public function configure()
{
$this->setWidget('name', new sfWidgetFormInput());
$this->setWidget('phone', new sfWidgetFormInput());
$this->setValidator('name', new sfValidatorPass(array('required' => false)));
$this->setValidator('phone', new sfValidatorPass(array('required' => false)));
}
private function leftJoinPersonalInfoQuery(Doctrine_Query $query)
{
if (isset($this->__leftJoinPersonalInfoQuery)) return;
$this->__leftJoinPersonalInfoQuery = true;
$query->leftJoin($query->getRootAlias().'.PersonalInfo pi');
}
public function addNameColumnQuery(Doctrine_Query $query, $field, $value)
{
$value = trim($value['text']);
if (!$value)
{
return;
}
$value = str_replace(' ', '%', $value);
$this->leftJoinPersonalInfoQuery($query);
$query->andWhere("CONCAT(pi.surname, ' ', pi.first_name, ' ', pi.patronymic) LIKE ?", "%$value%");
}
public function addPhoneColumnQuery(Doctrine_Query $query, $field, $value)
{
$value = trim($value['text']);
if (!$value)
{
return;
}
$value = str_replace(' ', '%', $value);
$this->leftJoinPersonalInfoQuery($query);
$query->andWhere("pi.mobile_phone LIKE ?", "%$value%");
}
}
You could try to analyse the return value of
$query->getDqlPart('from')to get this to work.