protected function setDocumentTypes()
{
$parentId = $this->getParentId();
$rows = $this->fetchAll($this->select(function (Select $select) use($parentId) {
if ($parentId !== null) {
$select->join(array('dtd' => 'document_type_dependency'), 'dtd.children_id = document_type.id', array());
$select->where->equalTo('dtd.parent_id', $parentId);
}
$select->order('name ASC');
}));
$documentTypes = array();
foreach ($rows as $row) {
$documentTypes[] = Model::fromArray((array) $row);
}
$this->setData('document_types', $documentTypes);
}