public static function hasWhere($relation, $where = [])
{
$model = new static();
$info = $model->{$relation}()->getRelationInfo();
switch ($info['type']) {
case Relation::HAS_ONE:
case Relation::HAS_MANY:
$table = $info['model']::getTable();
if (is_array($where)) {
foreach ($where as $key => $val) {
if (false === strpos($key, '.')) {
$where['b.' . $key] = $val;
unset($where[$key]);
}
}
}
return $model->db()->alias('a')->field('a.*')->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType'])->where($where);
case Relation::HAS_MANY_THROUGH:
// TODO
// TODO
default:
return $model;
}
}