public function getRelationHandler($criteria = null)
{
if (!$this->hasRecordRelation()) {
throw new TActiveRecordException('ar_undefined_relation_prop', $this->_property, get_class($this->_record), 'RELATIONS');
}
if ($criteria === null) {
$criteria = new TActiveRecordCriteria($this->getCondition(), $this->getParameters());
}
switch ($this->getRelationType()) {
case TActiveRecord::HAS_MANY:
return new TActiveRecordHasMany($this, $criteria);
case TActiveRecord::MANY_TO_MANY:
return new TActiveRecordHasManyAssociation($this, $criteria);
case TActiveRecord::HAS_ONE:
return new TActiveRecordHasOne($this, $criteria);
case TActiveRecord::BELONGS_TO:
return new TActiveRecordBelongsTo($this, $criteria);
default:
throw new TActiveRecordException('ar_invalid_relationship');
}
}