public static function getExternalConditions($select, $parentModel, $childName, $attributes)
{
$parentModelName = get_class($parentModel);
$parentTableName = $parentModel->getTableName();
// exhibitions
$childName = array_key_exists('source', $attributes) ? $attributes['source'] : $childName;
$childModelName = Inflector::classify($childName);
$childTableName = Bbx_Model::load($childModelName)->getTableName();
// images
if (!array_key_exists($childTableName, $select->getPart('from'))) {
$select->from($childTableName, array());
// images
}
if (array_key_exists('as', $attributes)) {
$refColumn = $attributes['as'] . '_id';
$polyType = $attributes['as'] . '_type';
} else {
$refColumn = Inflector::singularize($parentTableName) . '_id';
}
try {
$parentModel->getRowData();
$select->where("`" . $childTableName . "`.`" . $refColumn . "` = " . $parentModel->id);
} catch (Exception $e) {
$select->where("`" . $childTableName . "`.`" . $refColumn . "` = `" . $parentTableName . "`.`id`");
}
if (isset($polyType)) {
$select->where("`" . $childTableName . "`.`" . $polyType . "` = '" . Inflector::underscore($parentModelName) . "'");
}
return $select;
}