public function getErrors($attributeNameOrNames = null)
 {
     if (!$this->inside) {
         $this->inside = true;
         $errors = parent::getErrors($attributeNameOrNames);
         $this->inside = false;
     } else {
         $errors = array();
     }
     return $errors;
 }
 /**
  * Unrelates a model by index. Override to support finding opposing relation and making adjustment
  * so when accessing the opposing model, it will reflect properly the changes to the relation.
  * Ignoring when the relations are for the same model, because there is currently an issue with this being supported
  * with group/groups. Eventually todo: fix that and we can open it up to relations with the same model.
  */
 public function removeByIndex($i)
 {
     $model = $this->getByIndex($i);
     parent::removeByIndex($i);
     if (get_class($model) != get_class($this->relatedModel) && null != ($opposingRelationName = $this->getOpposingRelationName($model))) {
         $model->{$opposingRelationName} = null;
         $this->deferredUnrelatedModels[] = $model;
     }
 }
 public function save($runValidation = true)
 {
     if (!parent::save($runValidation)) {
         return false;
     }
     foreach ($this->deferredRelateBeans as $bean) {
         if ($this->linkType == RedBeanModel::LINK_TYPE_POLYMORPHIC) {
             if ($this->bean->id == null) {
                 R::store($this->bean);
             }
             $polyIdFieldName = strtolower($this->linkName) . '_id';
             $polyTypeFieldName = strtolower($this->linkName) . '_type';
             $bean->{$polyTypeFieldName} = $this->bean->getMeta('type');
             $bean->{$polyIdFieldName} = $this->bean->id;
             if (!RedBeanDatabase::isFrozen()) {
                 $tableName = RedBeanModel::getTableName($this->modelClassName);
                 RedBeanColumnTypeOptimizer::optimize($tableName, $polyIdFieldName, 'id');
             }
         } else {
             ZurmoRedBeanLinkManager::link($bean, $this->bean, $this->resolveLinkNameForCasing());
             if (!RedBeanDatabase::isFrozen()) {
                 $tableName = RedBeanModel::getTableName($this->modelClassName);
                 $columnName = RedBeanModel::getTableName($this->relatedModelClassName) . '_id';
                 $columnName = ZurmoRedBeanLinkManager::resolveColumnPrefix($this->resolveLinkNameForCasing()) . $columnName;
                 RedBeanColumnTypeOptimizer::optimize($tableName, $columnName, 'id');
             }
         }
         R::store($bean);
     }
     $this->deferredRelateBeans = array();
     $tableName = RedBeanModel::getTableName($this->relatedModelClassName);
     foreach ($this->deferredUnrelateBeans as $bean) {
         if (!$this->owns) {
             ZurmoRedBeanLinkManager::breakLink($bean, $tableName, $this->resolveLinkNameForCasing());
             R::store($bean);
         } else {
             R::trash($bean);
         }
     }
     $this->deferredUnrelateBeans = array();
     return true;
 }