public function getModel($defaults = []) : Model
    {
        // set table_alias
        if (!isset($defaults['table_alias'])) {
            if (!$this->table_alias) {
                $this->table_alias = $this->link;
                $this->table_alias = preg_replace('/_'.($this->owner->id_field ?: 'id').'/', '', $this->table_alias);
                $this->table_alias = preg_replace('/([a-zA-Z])[a-zA-Z]*[^a-zA-Z]*/', '\1', $this->table_alias);
                if (isset($this->owner->table_alias)) {
                    $this->table_alias = $this->owner->table_alias.'_'.$this->table_alias;
                }
            }
            $defaults['table_alias'] = $this->table_alias;
        }

        // if model is Closure, then call it and return model
        if (is_object($this->model) && $this->model instanceof \Closure) {
            $c = $this->model;
            $c = $c($this->owner, $this, $defaults);

            return $this->addToPersistence($c, $defaults);
        }

        // if model is set, then return clone of this model
        if (is_object($this->model)) {
            $c = clone $this->model;

            return $this->addToPersistence($c, $defaults);
        }

        // last effort - try to add model
        if (is_array($this->model)) {
            $model = $this->model[0];
            $md = $this->model;
            unset($md[0]);

            $defaults = array_merge($md, $defaults);
        } else {
            $model = $this->model;
        }

        if (!$model instanceof Model) {
            $model = $this->factory($model, $defaults);
        }

        return $this->addToPersistence($model, $defaults);
    }
public function getModel($defaults = []) : Model
    {
        // set table_alias
        if (!isset($defaults['table_alias'])) {
            if (!$this->table_alias) {
                $this->table_alias = $this->link;
                $this->table_alias = preg_replace('/_'.($this->owner->id_field ?: 'id').'/', '', $this->table_alias);
                $this->table_alias = preg_replace('/([a-zA-Z])[a-zA-Z]*[^a-zA-Z]*/', '\1', $this->table_alias);
                if (isset($this->owner->table_alias)) {
                    $this->table_alias = $this->owner->table_alias.'_'.$this->table_alias;
                }
            }
            $defaults['table_alias'] = $this->table_alias;
        }

        // if model is Closure, then call it and return model
        if (is_object($this->model) && $this->model instanceof \Closure) {
            $c = $this->model;
            $c = $c($this->owner, $this, $defaults);

            return $this->addToPersistence($c, $defaults);
        }

        // if model is set, then return clone of this model
        if (is_object($this->model)) {
            $c = clone $this->model;

            return $this->addToPersistence($c, $defaults);
        }

        // last effort - try to add model
        if (is_array($this->model)) {
            $model = $this->model[0];
            $md = $this->model;
            unset($md[0]);

            $defaults = array_merge($md, $defaults);
        } else {
            $model = $this->model;
        }

        if (!$model instanceof Model) {
            $model = $this->factory($model, $defaults);
        }

        return $this->addToPersistence($model, $defaults);
    }
public function getModel ( $ defaults = [ ] ) : Model { // set table_alias if ( ! isset ( $ defaults [ 'table_alias' ] ) ) { if ( ! $ this -> table_alias ) { $ this -> table_alias = $ this -> link ; $ this -> table_alias = preg_replace ( '/_' . ( $ this -> owner -> id_field ? : 'id' ) . '/' , '' , $ this -> table_alias ) ; $ this -> table_alias = preg_replace ( '/([a-zA-Z])[a-zA-Z]*[^a-zA-Z]*/' , '\1' , $ this -> table_alias ) ; if ( isset ( $ this -> owner -> table_alias ) ) { $ this -> table_alias = $ this -> owner -> table_alias . '_' . $ this -> table_alias ; } } $ defaults [ 'table_alias' ] = $ this -> table_alias ; } // if model is Closure, then call it and return model if ( is_object ( $ this -> model ) && $ this -> model instanceof \ Closure ) { $ c = $ this -> model ; $ c = $ c ( $ this -> owner , $ this , $ defaults ) ; return $ this -> addToPersistence ( $ c , $ defaults ) ; } // if model is set, then return clone of this model if ( is_object ( $ this -> model ) ) { $ c = clone $ this -> model ; return $ this -> addToPersistence ( $ c , $ defaults ) ; } // last effort - try to add model if ( is_array ( $ this -> model ) ) { $ model = $ this -> model [ 0 ] ; $ md = $ this -> model ; unset ( $ md [ 0 ] ) ; $ defaults = array_merge ( $ md , $ defaults ) ; } else { $ model = $ this -> model ; } if ( ! $ model instanceof Model ) { $ model = $ this -> factory ( $ model , $ defaults ) ; } return $ this -> addToPersistence ( $ model , $ defaults ) ; }
Returns destination model that is linked through this reference. Will apply
necessary conditions.

@param array $defaults Properties

@return Model
Returns destination model that is linked through this reference . Will apply necessary conditions .