/**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aAuthor !== null) {
             if ($this->aAuthor->isModified() || $this->aAuthor->isNew()) {
                 $affectedRows += $this->aAuthor->save($con);
             }
             $this->setAuthor($this->aAuthor);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aAuthor !== null) {
             if ($this->aAuthor->isModified() || $this->aAuthor->isNew()) {
                 $affectedRows += $this->aAuthor->save($con);
             }
             $this->setAuthor($this->aAuthor);
         }
         if ($this->aArticle !== null) {
             if ($this->aArticle->isModified() || $this->aArticle->isNew()) {
                 $affectedRows += $this->aArticle->save($con);
             }
             $this->setArticle($this->aArticle);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = AuthorArticlePeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setNew(false);
             } else {
                 $affectedRows += AuthorArticlePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aAuthor !== null) {
             if ($this->aAuthor->isModified() || $this->aAuthor->isNew()) {
                 $affectedRows += $this->aAuthor->save($con);
             }
             $this->setAuthor($this->aAuthor);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = BookPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $criteria = $this->buildCriteria();
                 if ($criteria->keyContainsValue(BookPeer::ID)) {
                     throw new PropelException('Cannot insert a value for auto-increment primary key (' . BookPeer::ID . ')');
                 }
                 $pk = BasePeer::doInsert($criteria, $con);
                 $affectedRows += 1;
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += BookPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 public function testIsModifiedAndNullValues()
 {
     $a = new Author();
     $a->setFirstName('');
     $a->setLastName('Bar');
     $a->setAge(0);
     $a->save();
     $a->setFirstName(null);
     $this->assertTrue($a->isModified(), "Expected Author to be modified after changing empty string column value to NULL.");
     $a->setAge(null);
     $this->assertTrue($a->isModified(), "Expected Author to be modified after changing 0-value int column to NULL.");
     $a->setFirstName('');
     $this->assertTrue($a->isModified(), "Expected Author to be modified after changing NULL column value to empty string.");
     $a->setAge(0);
     $this->assertTrue($a->isModified(), "Expected Author to be modified after changing NULL column to 0-value int.");
 }
 /**
  * Test for correct reporting of isModified().
  */
 public function testIsModified()
 {
     // 1) Basic test
     $a = new Author();
     $a->setFirstName("John");
     $a->setLastName("Doe");
     $a->setAge(25);
     $this->assertTrue($a->isModified(), "Expected Author to be modified after setting values.");
     $a->save();
     $this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
     // 2) Test behavior with setting vars of different types
     // checking setting int col to string val
     $a->setAge('25');
     $this->assertFalse($a->isModified(), "Expected Author to be unmodified after setting int column to string-cast of same value.");
     $a->setFirstName("John2");
     $this->assertTrue($a->isModified(), "Expected Author to be modified after changing string column value.");
     // checking setting string col to int val
     $a->setFirstName("1");
     $a->save();
     $this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
     $a->setFirstName(1);
     $this->assertFalse($a->isModified(), "Expected Author to be unmodified after setting string column to int-cast of same value.");
     // 3) Test for appropriate behavior of NULL
     // checking "" -> NULL
     $a->setFirstName("");
     $a->save();
     $this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
     $a->setFirstName(null);
     $this->assertTrue($a->isModified(), "Expected Author to be modified after changing empty string column value to NULL.");
     $a->setFirstName("John");
     $a->setAge(0);
     $a->save();
     $this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
     $a->setAge(null);
     $this->assertTrue($a->isModified(), "Expected Author to be modified after changing 0-value int column to NULL.");
     $a->save();
     $this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
     $a->setAge(0);
     $this->assertTrue($a->isModified(), "Expected Author to be modified after changing NULL-value int column to 0.");
 }