/** * Takes an attribute name and makes sure appropriate relationships are included. * * This will take an attribute name many layers of relationship deep, make sure that all appropriate tables are * included with the result and return a string that is then acceptable to be used in a where clause. * * @param CDbCriteria $criteria * @param string $attribute * @param string $search * * @return string */ protected function relationalAttribute(CDbCriteria $criteria, $attribute, $search) { $search = $this->model->getTableAlias() . '.' . $search; if (strpos($attribute, '.')) { $relationship = explode('.', $attribute); $relationshipArray = array(); while (count($relationship) > 1) { $relationshipString = array_shift($relationship); $search = $relationshipString; if (count($relationshipArray)) { $relationshipString = implode('.', $relationshipArray) . '.' . $relationshipString; } $relationshipArray[] = $relationshipString; } $search .= '.' . array_shift($relationship); $criteria->together = true; $criteria->with = array_merge($criteria->with, $relationshipArray); } return $search; }