src/CarteBlanche/Library/AutoObject/AutoObject.php
protected function _buildRelations()
    {
        $db = CarteBlanche::getContainer()->get('entity_manager')
            ->getStorageEngine($this->getDatabaseName());

        foreach ($this->getStructureEntry('structure') as $_field=>$_fdata) {
            $_relobject=$_relfield=null;

            if ($_field!='parent_id' && preg_match('/^(.*)_id$/i', $_field, $matches)) {
                if (isset($matches[1]) && is_string($matches[1]))
                    $_relobject = $matches[1];
                $_relfield = 'id';
                $_intfield = $_field;
                $_field = str_replace('_id', '', $_field);
            } elseif (!empty($_fdata['related'])) {
                $_relobject_f = $_fdata['related'];
                if (!substr_count($_relobject_f, ':')) $_relobject_f .= ':id';
                $matches = explode(':', $_relobject_f);
                $_relobject = $matches[0];
                $_relfield = $matches[1];
                $_intfield = $_field;
                $_field = 'parent';
            }

            if (isset($_relobject) && $_relobject==$this->getTableName()) {
                $this->object_relations->setEntry( $_field, array(
                    'related_table'=>$_relobject,
                    'related_field'=>$_relfield,
                    'internal_field'=>$_intfield,
                    'model'=>$this->getModel()->getModelClone(),
                    'slug_field'=>$this->getModel()->getSlugField(),
                    'self'=>true
                ));
            } elseif (isset($_relobject) && $db->table_exists($_relobject)) {
                $_relobject_structure = AutoObjectMapper::getAutoObject( $_relobject, $this->getDatabaseName() );
                if (!empty($_relobject_structure))
                    $_related = $_relobject_structure->getModel();
                $this->object_relations->setEntry( $_field, array(
                    'related_table'=>$_relobject,
                    'related_field'=>$_relfield,
                    'internal_field'=>$_intfield,
                    'model'=>$_related,
                    'slug_field'=>$_related->getSlugField(),
                ));
            }

        }

        $_relobject_f=null;
        if (!empty($this->getModel()->_has_many))
        foreach ($this->getModel()->_has_many as $_relname=>$_relobject_f) {
            $_relobject=$_relfield=null;

            if (!substr_count($_relobject_f, ':')) $_relobject_f .= ':id';
            $matches = explode(':', $_relobject_f);
            $_relobject = $matches[0];
            $_relfield = $matches[1];

            if (isset($_relobject) && $_relobject==$this->getTableName()) {
                $this->object_relations->setEntry( $_relname, array(
                    'related_table'=>$_relobject,
                    'related_field'=>$_relfield,
                    'internal_field'=>'id',
                    'model'=>$this->getModel()->getModelClone(),
                    'slug_field'=>$this->getModel()->getSlugField(),
                    'is_many'=>true,
                    'self'=>true
                ));
            } elseif (isset($_relobject) && $db->table_exists($_relobject)) {
                $_relobject_structure = AutoObjectMapper::getAutoObject( $_relobject, $this->getDatabaseName() );
                if (!empty($_relobject_structure)) {
                    $_related = $_relobject_structure->getModel();
                    $this->object_relations->setEntry( $_relname, array(
                        'related_table'=>$_relobject,
                        'related_field'=>$_relfield,
                        'internal_field'=>'id',
                        'model'=>$_related,
                        'slug_field'=>$_related->getSlugField(),
                        'is_many'=>true
                    ));
                } else {
                    throw new \RuntimeException( "Table structure for related field '$_relname' not found!");
                }
            }
        }
    }
protected function _buildRelations()
    {
        $db = CarteBlanche::getContainer()->get('entity_manager')
            ->getStorageEngine($this->getDatabaseName());

        foreach ($this->getStructureEntry('structure') as $_field=>$_fdata) {
            $_relobject=$_relfield=null;

            if ($_field!='parent_id' && preg_match('/^(.*)_id$/i', $_field, $matches)) {
                if (isset($matches[1]) && is_string($matches[1]))
                    $_relobject = $matches[1];
                $_relfield = 'id';
                $_intfield = $_field;
                $_field = str_replace('_id', '', $_field);
            } elseif (!empty($_fdata['related'])) {
                $_relobject_f = $_fdata['related'];
                if (!substr_count($_relobject_f, ':')) $_relobject_f .= ':id';
                $matches = explode(':', $_relobject_f);
                $_relobject = $matches[0];
                $_relfield = $matches[1];
                $_intfield = $_field;
                $_field = 'parent';
            }

            if (isset($_relobject) && $_relobject==$this->getTableName()) {
                $this->object_relations->setEntry( $_field, array(
                    'related_table'=>$_relobject,
                    'related_field'=>$_relfield,
                    'internal_field'=>$_intfield,
                    'model'=>$this->getModel()->getModelClone(),
                    'slug_field'=>$this->getModel()->getSlugField(),
                    'self'=>true
                ));
            } elseif (isset($_relobject) && $db->table_exists($_relobject)) {
                $_relobject_structure = AutoObjectMapper::getAutoObject( $_relobject, $this->getDatabaseName() );
                if (!empty($_relobject_structure))
                    $_related = $_relobject_structure->getModel();
                $this->object_relations->setEntry( $_field, array(
                    'related_table'=>$_relobject,
                    'related_field'=>$_relfield,
                    'internal_field'=>$_intfield,
                    'model'=>$_related,
                    'slug_field'=>$_related->getSlugField(),
                ));
            }

        }

        $_relobject_f=null;
        if (!empty($this->getModel()->_has_many))
        foreach ($this->getModel()->_has_many as $_relname=>$_relobject_f) {
            $_relobject=$_relfield=null;

            if (!substr_count($_relobject_f, ':')) $_relobject_f .= ':id';
            $matches = explode(':', $_relobject_f);
            $_relobject = $matches[0];
            $_relfield = $matches[1];

            if (isset($_relobject) && $_relobject==$this->getTableName()) {
                $this->object_relations->setEntry( $_relname, array(
                    'related_table'=>$_relobject,
                    'related_field'=>$_relfield,
                    'internal_field'=>'id',
                    'model'=>$this->getModel()->getModelClone(),
                    'slug_field'=>$this->getModel()->getSlugField(),
                    'is_many'=>true,
                    'self'=>true
                ));
            } elseif (isset($_relobject) && $db->table_exists($_relobject)) {
                $_relobject_structure = AutoObjectMapper::getAutoObject( $_relobject, $this->getDatabaseName() );
                if (!empty($_relobject_structure)) {
                    $_related = $_relobject_structure->getModel();
                    $this->object_relations->setEntry( $_relname, array(
                        'related_table'=>$_relobject,
                        'related_field'=>$_relfield,
                        'internal_field'=>'id',
                        'model'=>$_related,
                        'slug_field'=>$_related->getSlugField(),
                        'is_many'=>true
                    ));
                } else {
                    throw new \RuntimeException( "Table structure for related field '$_relname' not found!");
                }
            }
        }
    }
Build an array of the object relation fields
@return void