public function save($validate_datatype = false)
    {
        $state = $this->getState();
        if ($state == self::STATE_DELETED) {
            throw new Exception\LogicException(__METHOD__ . "Record has already been deleted in database.");
        }

        switch ($state) {
            case self::STATE_NEW:
                // Means insert
                $new_record = $this->getTable()->insert($this->toArray(), $validate_datatype);
                break;
            case self::STATE_CLEAN:
            case self::STATE_DIRTY:
                // Means update
                $predicate = $this->getRecordPrimaryKeyPredicate();
                $this->getTable()->update($this->toArray(), $predicate, $combination = Predicate\PredicateSet::OP_AND, $validate_datatype);
                $new_record = $this->getTable()->findOneBy($predicate);
                break;
                //@codeCoverageIgnoreStart
            default:
                throw new Exception\LogicException(__METHOD__ . ": Record is not on manageable state.");
                //@codeCoverageIgnoreEnd
        }
        /*
        if ($state == self::STATE_NEW) {
            // Means insert
            $new_record = $this->getTable()->insert($data, $validate_datatype);

        } elseif ($state == self::STATE_CLEAN || $state == self::STATE_DIRTY) {
            // Means update
            $predicate = $this->getRecordPrimaryKeyPredicate();
            $this->getTable()->update($data, $predicate, $combination=Predicate\PredicateSet::OP_AND, $validate_datatype);
            $new_record = $this->getTable()->findOneBy($predicate);
        } else {
             //@codeCoverageIgnoreStart

            throw new Exception\LogicException(__METHOD__ . ": Record is not on manageable state.");
             //@codeCoverageIgnoreEnd
        }

         */
        $this->setData($new_record->toArray());
        $this->setState(Record::STATE_CLEAN);
        unset($new_record);
        return $this;
    }
public function save($validate_datatype = false)
    {
        $state = $this->getState();
        if ($state == self::STATE_DELETED) {
            throw new Exception\LogicException(__METHOD__ . "Record has already been deleted in database.");
        }

        switch ($state) {
            case self::STATE_NEW:
                // Means insert
                $new_record = $this->getTable()->insert($this->toArray(), $validate_datatype);
                break;
            case self::STATE_CLEAN:
            case self::STATE_DIRTY:
                // Means update
                $predicate = $this->getRecordPrimaryKeyPredicate();
                $this->getTable()->update($this->toArray(), $predicate, $combination = Predicate\PredicateSet::OP_AND, $validate_datatype);
                $new_record = $this->getTable()->findOneBy($predicate);
                break;
                //@codeCoverageIgnoreStart
            default:
                throw new Exception\LogicException(__METHOD__ . ": Record is not on manageable state.");
                //@codeCoverageIgnoreEnd
        }
        /*
        if ($state == self::STATE_NEW) {
            // Means insert
            $new_record = $this->getTable()->insert($data, $validate_datatype);

        } elseif ($state == self::STATE_CLEAN || $state == self::STATE_DIRTY) {
            // Means update
            $predicate = $this->getRecordPrimaryKeyPredicate();
            $this->getTable()->update($data, $predicate, $combination=Predicate\PredicateSet::OP_AND, $validate_datatype);
            $new_record = $this->getTable()->findOneBy($predicate);
        } else {
             //@codeCoverageIgnoreStart

            throw new Exception\LogicException(__METHOD__ . ": Record is not on manageable state.");
             //@codeCoverageIgnoreEnd
        }

         */
        $this->setData($new_record->toArray());
        $this->setState(Record::STATE_CLEAN);
        unset($new_record);
        return $this;
    }
public function save ( $ validate_datatype = false ) { $ state = $ this -> getState ( ) ; if ( $ state == self :: STATE_DELETED ) { throw new Exception \ LogicException ( __METHOD__ . "Record has already been deleted in database." ) ; } switch ( $ state ) { case self :: STATE_NEW : // Means insert $ new_record = $ this -> getTable ( ) -> insert ( $ this -> toArray ( ) , $ validate_datatype ) ; break ; case self :: STATE_CLEAN : case self :: STATE_DIRTY : // Means update $ predicate = $ this -> getRecordPrimaryKeyPredicate ( ) ; $ this -> getTable ( ) -> update ( $ this -> toArray ( ) , $ predicate , $ combination = Predicate \ PredicateSet :: OP_AND , $ validate_datatype ) ; $ new_record = $ this -> getTable ( ) -> findOneBy ( $ predicate ) ; break ; //@codeCoverageIgnoreStart default : throw new Exception \ LogicException ( __METHOD__ . ": Record is not on manageable state." ) ; //@codeCoverageIgnoreEnd } /*
        if ($state == self::STATE_NEW) {
            // Means insert
            $new_record = $this->getTable()->insert($data, $validate_datatype);

        } elseif ($state == self::STATE_CLEAN || $state == self::STATE_DIRTY) {
            // Means update
            $predicate = $this->getRecordPrimaryKeyPredicate();
            $this->getTable()->update($data, $predicate, $combination=Predicate\PredicateSet::OP_AND, $validate_datatype);
            $new_record = $this->getTable()->findOneBy($predicate);
        } else {
             //@codeCoverageIgnoreStart

            throw new Exception\LogicException(__METHOD__ . ": Record is not on manageable state.");
             //@codeCoverageIgnoreEnd
        }

         */ $ this -> setData ( $ new_record -> toArray ( ) ) ; $ this -> setState ( Record :: STATE_CLEAN ) ; unset ( $ new_record ) ; return $ this ; }
Save a record in database

@throws Exception\LogicException when record has already been deleted

@param boolean $validate_datatype if true will ensure record data correspond to column datatype

@return Record freshly modified record (from database)
Save a record in database