public function save($automatic_reload = true)
    {
        // Run Pre-saver.
        $this->preSave();

        // Run Field Fixer.
        $this->__fieldFix();

        // Calculate row to save_down
        $this->__calculateSaveDownRows();
        $primary_key_column = $this->getIDField();

        // Make an array out of the objects columns.
        $data = array();
        foreach ($this->_columns as $column) {
            // Never update the primary key. Bad bad bad. Except if we're versioned.
            if ($column != $primary_key_column ||
              $this instanceof VersionedActiveRecord ||
              $this->_force_insert
            ) {
                $data["`{$column}`"] = $this->$column;
            }
        }

        // If we already have an ID, this is an update.
        $database = DatabaseLayer::getInstance();
        if (!$this->getId() ||
          (property_exists($this, '_is_versioned') && $this->_is_versioned == true) ||
          $this->_force_insert
        ) {
            $operation = $database->insert($this->getTableName(), $this->getTableAlias());
            $this->_force_insert = false;
        } else { // Else, we're an insert.
            $operation = $database->update($this->getTableName(), $this->getTableAlias());
        }

        $operation->setData($data);

        if ($this->getId() && $primary_key_column) {
            $operation->condition($primary_key_column, $this->$primary_key_column);
            $operation->execute();
        } else { // Else, we're an insert.
            $new_id = $operation->execute($this->getClass());
            if ($primary_key_column) {
                $this->$primary_key_column = $new_id;
            }
        }

        // Expire cache.
        if (DatabaseLayer::getInstance()->useCache()) {
            $cache = DatabaseLayer::getInstance()->getCache();
            $cache->delete($this->getCacheIdentifier());
        }

        // Expire any existing copy of this object.
        SearchIndex::getInstance()->expire(get_called_class() . "/" . $this->getTableName(), $this->getId());

        if ($automatic_reload && $primary_key_column) {
            $this->reload();
        }

        // Run Post Save.
        $this->postSave();

        // Return object. Should this return true/false based on success instead?
        return $this;
    }
public function save($automatic_reload = true)
    {
        // Run Pre-saver.
        $this->preSave();

        // Run Field Fixer.
        $this->__fieldFix();

        // Calculate row to save_down
        $this->__calculateSaveDownRows();
        $primary_key_column = $this->getIDField();

        // Make an array out of the objects columns.
        $data = array();
        foreach ($this->_columns as $column) {
            // Never update the primary key. Bad bad bad. Except if we're versioned.
            if ($column != $primary_key_column ||
              $this instanceof VersionedActiveRecord ||
              $this->_force_insert
            ) {
                $data["`{$column}`"] = $this->$column;
            }
        }

        // If we already have an ID, this is an update.
        $database = DatabaseLayer::getInstance();
        if (!$this->getId() ||
          (property_exists($this, '_is_versioned') && $this->_is_versioned == true) ||
          $this->_force_insert
        ) {
            $operation = $database->insert($this->getTableName(), $this->getTableAlias());
            $this->_force_insert = false;
        } else { // Else, we're an insert.
            $operation = $database->update($this->getTableName(), $this->getTableAlias());
        }

        $operation->setData($data);

        if ($this->getId() && $primary_key_column) {
            $operation->condition($primary_key_column, $this->$primary_key_column);
            $operation->execute();
        } else { // Else, we're an insert.
            $new_id = $operation->execute($this->getClass());
            if ($primary_key_column) {
                $this->$primary_key_column = $new_id;
            }
        }

        // Expire cache.
        if (DatabaseLayer::getInstance()->useCache()) {
            $cache = DatabaseLayer::getInstance()->getCache();
            $cache->delete($this->getCacheIdentifier());
        }

        // Expire any existing copy of this object.
        SearchIndex::getInstance()->expire(get_called_class() . "/" . $this->getTableName(), $this->getId());

        if ($automatic_reload && $primary_key_column) {
            $this->reload();
        }

        // Run Post Save.
        $this->postSave();

        // Return object. Should this return true/false based on success instead?
        return $this;
    }
public function save ( $ automatic_reload = true ) { // Run Pre-saver. $ this -> preSave ( ) ; // Run Field Fixer. $ this -> __fieldFix ( ) ; // Calculate row to save_down $ this -> __calculateSaveDownRows ( ) ; $ primary_key_column = $ this -> getIDField ( ) ; // Make an array out of the objects columns. $ data = array ( ) ; foreach ( $ this -> _columns as $ column ) { // Never update the primary key. Bad bad bad. Except if we're versioned. if ( $ column != $ primary_key_column || $ this instanceof VersionedActiveRecord || $ this -> _force_insert ) { $ data [ "`{$column}`" ] = $ this -> $ column ; } } // If we already have an ID, this is an update. $ database = DatabaseLayer :: getInstance ( ) ; if ( ! $ this -> getId ( ) || ( property_exists ( $ this , '_is_versioned' ) && $ this -> _is_versioned == true ) || $ this -> _force_insert ) { $ operation = $ database -> insert ( $ this -> getTableName ( ) , $ this -> getTableAlias ( ) ) ; $ this -> _force_insert = false ; } else { // Else, we're an insert. $ operation = $ database -> update ( $ this -> getTableName ( ) , $ this -> getTableAlias ( ) ) ; } $ operation -> setData ( $ data ) ; if ( $ this -> getId ( ) && $ primary_key_column ) { $ operation -> condition ( $ primary_key_column , $ this -> $ primary_key_column ) ; $ operation -> execute ( ) ; } else { // Else, we're an insert. $ new_id = $ operation -> execute ( $ this -> getClass ( ) ) ; if ( $ primary_key_column ) { $ this -> $ primary_key_column = $ new_id ; } } // Expire cache. if ( DatabaseLayer :: getInstance ( ) -> useCache ( ) ) { $ cache = DatabaseLayer :: getInstance ( ) -> getCache ( ) ; $ cache -> delete ( $ this -> getCacheIdentifier ( ) ) ; } // Expire any existing copy of this object. SearchIndex :: getInstance ( ) -> expire ( get_called_class ( ) . "/" . $ this -> getTableName ( ) , $ this -> getId ( ) ) ; if ( $ automatic_reload && $ primary_key_column ) { $ this -> reload ( ) ; } // Run Post Save. $ this -> postSave ( ) ; // Return object. Should this return true/false based on success instead? return $ this ; }
Save the selected record.
This will do an INSERT or UPDATE as appropriate

@param boolean $automatic_reload Whether or not to automatically reload

@return ActiveRecord
Save the selected record . This will do an INSERT or UPDATE as appropriate