/** * Test default return values. */ public function testDefaultValues() { $r = new Review(); $this->assertEquals('2001-01-01', $r->getReviewDate('Y-m-d')); $this->assertFalse($r->isModified(), "expected isModified() to be false"); $acct = new BookstoreEmployeeAccount(); $this->assertEquals(true, $acct->getEnabled()); $this->assertFalse($acct->isModified()); $acct->setLogin("testuser"); $acct->setPassword("testpass"); $this->assertTrue($acct->isModified()); }
/** * Test the behavior of date/time/values. * This requires that the model was built with propel.useDateTimeClass=true. */ public function testTemporalValues_PreEpoch() { $r = new Review(); $preEpochDate = new DateTime('1602-02-02'); $r->setReviewDate($preEpochDate); $this->assertEquals('1602-02-02', $r->getReviewDate(null)->format("Y-m-d")); $r->setReviewDate('1702-02-02'); $this->assertTrue($r->isModified()); $this->assertEquals('1702-02-02', $r->getReviewDate(null)->format("Y-m-d")); // Now test for setting null $r->setReviewDate(null); $this->assertNull($r->getReviewDate()); }
/** * 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->aSeries !== null) { if ($this->aSeries->isModified() || $this->aSeries->isNew()) { $affectedRows += $this->aSeries->save($con); } $this->setSeries($this->aSeries); } if ($this->aReview !== null) { if ($this->aReview->isModified() || $this->aReview->isNew()) { $affectedRows += $this->aReview->save($con); } $this->setReview($this->aReview); } if ($this->aScore !== null) { if ($this->aScore->isModified() || $this->aScore->isNew()) { $affectedRows += $this->aScore->save($con); } $this->setScore($this->aScore); } if ($this->isNew()) { $this->modifiedColumns[] = ModelPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = ModelPeer::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->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += ModelPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collConfigs !== null) { foreach ($this->collConfigs as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collReviews !== null) { foreach ($this->collReviews as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collScores !== null) { foreach ($this->collScores as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collUserMetas !== null) { foreach ($this->collUserMetas as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }