src/RocknRoot/StrayFw/Database/Postgres/Model.php
public function save() : bool
    {
        $status = false;
        if ($this->new === false) {
            if ($this->deletionFlag === true) {
                $status = $this->delete();
            } elseif (count($this->modified) > 0) {
                $updateQuery = new Update($this->getDatabaseName());
                $updateQuery->update($this->getTableName());

                $where = array();
                foreach ($this->getPrimary() as $primary) {
                    $field = $this->{'field' . ucfirst($primary)};
                    $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($primary)));
                    $where[$realName] = ':primary' . ucfirst($primary);
                    $updateQuery->bind('primary' . ucfirst($primary), $field['value']);
                }
                $updateQuery->where($where);

                $set = array();
                foreach ($this->modified as $key => $value) {
                    if ($value === true) {
                        $field = $this->{'field' . ucfirst($key)};
                        $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($key)));
                        $set[$realName] = ':field' . ucfirst($key);
                        $updateQuery->bind(':field' . ucfirst($key), $field['value']);
                    }
                }
                $updateQuery->set($set);

                $this->modified = array();

                $status = $updateQuery->execute();
            }
        } else {
            if ($this->deletionFlag === false) {
                $insertQuery = new Insert($this->getDatabaseName());
                $insertQuery->into($this->getTableName());

                $returning = array();
                foreach ($this->getPrimary() as $primary) {
                    $field = $this->{'field' . ucfirst($primary)};
                    $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($primary)));
                    $returning[] = $realName;
                }
                $insertQuery->returning($returning);

                $values = array();
                foreach ($this->getAllFieldsAliases() as $name) {
                    $field = $this->{'field' . ucfirst($name)};
                    if (isset($field['value']) === true) {
                        $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($name)));
                        $values[$realName] = ':field' . ucfirst($name);
                        $insertQuery->bind('field' . ucfirst($name), $field['value']);
                    }
                }
                $insertQuery->values($values);

                $status = $insertQuery->execute();

                if ($status === true) {
                    $this->modified = array();
                    $rows = $insertQuery->getStatement()->fetch(\PDO::FETCH_ASSOC);
                    $imax = count($rows);
                    for ($i = 0; $i < $imax; $i++) {
                        $field = &$this->{'field' . ucfirst($this->getPrimary()[$i])};
                        $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($this->getPrimary()[$i])));
                        $realName = substr($realName, stripos($realName, '.') + 1);
                        $field['value'] = $rows[$realName];
                    }
                    $this->new = false;
                }
            }
        }

        return $status;
    }
public function save() : bool
    {
        $status = false;
        if ($this->new === false) {
            if ($this->deletionFlag === true) {
                $status = $this->delete();
            } elseif (count($this->modified) > 0) {
                $updateQuery = new Update($this->getDatabaseName());
                $updateQuery->update($this->getTableName());

                $where = array();
                foreach ($this->getPrimary() as $primary) {
                    $field = $this->{'field' . ucfirst($primary)};
                    $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($primary)));
                    $where[$realName] = ':primary' . ucfirst($primary);
                    $updateQuery->bind('primary' . ucfirst($primary), $field['value']);
                }
                $updateQuery->where($where);

                $set = array();
                foreach ($this->modified as $key => $value) {
                    if ($value === true) {
                        $field = $this->{'field' . ucfirst($key)};
                        $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($key)));
                        $set[$realName] = ':field' . ucfirst($key);
                        $updateQuery->bind(':field' . ucfirst($key), $field['value']);
                    }
                }
                $updateQuery->set($set);

                $this->modified = array();

                $status = $updateQuery->execute();
            }
        } else {
            if ($this->deletionFlag === false) {
                $insertQuery = new Insert($this->getDatabaseName());
                $insertQuery->into($this->getTableName());

                $returning = array();
                foreach ($this->getPrimary() as $primary) {
                    $field = $this->{'field' . ucfirst($primary)};
                    $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($primary)));
                    $returning[] = $realName;
                }
                $insertQuery->returning($returning);

                $values = array();
                foreach ($this->getAllFieldsAliases() as $name) {
                    $field = $this->{'field' . ucfirst($name)};
                    if (isset($field['value']) === true) {
                        $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($name)));
                        $values[$realName] = ':field' . ucfirst($name);
                        $insertQuery->bind('field' . ucfirst($name), $field['value']);
                    }
                }
                $insertQuery->values($values);

                $status = $insertQuery->execute();

                if ($status === true) {
                    $this->modified = array();
                    $rows = $insertQuery->getStatement()->fetch(\PDO::FETCH_ASSOC);
                    $imax = count($rows);
                    for ($i = 0; $i < $imax; $i++) {
                        $field = &$this->{'field' . ucfirst($this->getPrimary()[$i])};
                        $realName = constant(get_called_class() . '::FIELD_' . strtoupper(Helper::codifyName($this->getPrimary()[$i])));
                        $realName = substr($realName, stripos($realName, '.') + 1);
                        $field['value'] = $rows[$realName];
                    }
                    $this->new = false;
                }
            }
        }

        return $status;
    }
public function save ( ) : bool { $ status = false ; if ( $ this -> new === false ) { if ( $ this -> deletionFlag === true ) { $ status = $ this -> delete ( ) ; } elseif ( count ( $ this -> modified ) > 0 ) { $ updateQuery = new Update ( $ this -> getDatabaseName ( ) ) ; $ updateQuery -> update ( $ this -> getTableName ( ) ) ; $ where = array ( ) ; foreach ( $ this -> getPrimary ( ) as $ primary ) { $ field = $ this -> { 'field' . ucfirst ( $ primary ) } ; $ realName = constant ( get_called_class ( ) . '::FIELD_' . strtoupper ( Helper :: codifyName ( $ primary ) ) ) ; $ where [ $ realName ] = ':primary' . ucfirst ( $ primary ) ; $ updateQuery -> bind ( 'primary' . ucfirst ( $ primary ) , $ field [ 'value' ] ) ; } $ updateQuery -> where ( $ where ) ; $ set = array ( ) ; foreach ( $ this -> modified as $ key => $ value ) { if ( $ value === true ) { $ field = $ this -> { 'field' . ucfirst ( $ key ) } ; $ realName = constant ( get_called_class ( ) . '::FIELD_' . strtoupper ( Helper :: codifyName ( $ key ) ) ) ; $ set [ $ realName ] = ':field' . ucfirst ( $ key ) ; $ updateQuery -> bind ( ':field' . ucfirst ( $ key ) , $ field [ 'value' ] ) ; } } $ updateQuery -> set ( $ set ) ; $ this -> modified = array ( ) ; $ status = $ updateQuery -> execute ( ) ; } } else { if ( $ this -> deletionFlag === false ) { $ insertQuery = new Insert ( $ this -> getDatabaseName ( ) ) ; $ insertQuery -> into ( $ this -> getTableName ( ) ) ; $ returning = array ( ) ; foreach ( $ this -> getPrimary ( ) as $ primary ) { $ field = $ this -> { 'field' . ucfirst ( $ primary ) } ; $ realName = constant ( get_called_class ( ) . '::FIELD_' . strtoupper ( Helper :: codifyName ( $ primary ) ) ) ; $ returning [ ] = $ realName ; } $ insertQuery -> returning ( $ returning ) ; $ values = array ( ) ; foreach ( $ this -> getAllFieldsAliases ( ) as $ name ) { $ field = $ this -> { 'field' . ucfirst ( $ name ) } ; if ( isset ( $ field [ 'value' ] ) === true ) { $ realName = constant ( get_called_class ( ) . '::FIELD_' . strtoupper ( Helper :: codifyName ( $ name ) ) ) ; $ values [ $ realName ] = ':field' . ucfirst ( $ name ) ; $ insertQuery -> bind ( 'field' . ucfirst ( $ name ) , $ field [ 'value' ] ) ; } } $ insertQuery -> values ( $ values ) ; $ status = $ insertQuery -> execute ( ) ; if ( $ status === true ) { $ this -> modified = array ( ) ; $ rows = $ insertQuery -> getStatement ( ) -> fetch ( \ PDO :: FETCH_ASSOC ) ; $ imax = count ( $ rows ) ; for ( $ i = 0 ; $ i < $ imax ; $ i ++ ) { $ field = & $ this -> { 'field' . ucfirst ( $ this -> getPrimary ( ) [ $ i ] ) } ; $ realName = constant ( get_called_class ( ) . '::FIELD_' . strtoupper ( Helper :: codifyName ( $ this -> getPrimary ( ) [ $ i ] ) ) ) ; $ realName = substr ( $ realName , stripos ( $ realName , '.' ) + 1 ) ; $ field [ 'value' ] = $ rows [ $ realName ] ; } $ this -> new = false ; } } } return $ status ; }
Save the model. Delete if deletionFlag is true.

@return bool true if successfully saved
Save the model . Delete if deletionFlag is true .