本文整理汇总了PHP中AuthorPeer::doDelete方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthorPeer::doDelete方法的具体用法?PHP AuthorPeer::doDelete怎么用?PHP AuthorPeer::doDelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthorPeer
的用法示例。
在下文中一共展示了AuthorPeer::doDelete方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
public function delete($con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($con === null) {
$con = Propel::getConnection(AuthorPeer::DATABASE_NAME);
}
try {
$con->begin();
AuthorPeer::doDelete($this, $con);
$this->setDeleted(true);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
示例2: testScenario
//.........这里部分代码省略.........
$this->assertTrue($ret3, 'complex validation can pass');
// Testing doCount() functionality
// -------------------------------
$c = new Criteria();
$records = BookPeer::doSelect($c);
$count = BookPeer::doCount($c);
$this->assertEquals($count, count($records), 'correct number of results');
// Test many-to-many relationships
// ---------------
// init book club list 1 with 2 books
$blc1 = new BookClubList();
$blc1->setGroupLeader("Crazyleggs");
$blc1->setTheme("Happiness");
$brel1 = new BookListRel();
$brel1->setBook($phoenix);
$brel2 = new BookListRel();
$brel2->setBook($dj);
$blc1->addBookListRel($brel1);
$blc1->addBookListRel($brel2);
$blc1->save();
$this->assertNotNull($blc1->getId(), 'BookClubList 1 was saved');
// init book club list 2 with 1 book
$blc2 = new BookClubList();
$blc2->setGroupLeader("John Foo");
$blc2->setTheme("Default");
$brel3 = new BookListRel();
$brel3->setBook($phoenix);
$blc2->addBookListRel($brel3);
$blc2->save();
$this->assertNotNull($blc2->getId(), 'BookClubList 2 was saved');
// re-fetch books and lists from db to be sure that nothing is cached
$crit = new Criteria();
$crit->add(BookPeer::ID, $phoenix->getId());
$phoenix = BookPeer::doSelectOne($crit);
$this->assertNotNull($phoenix, "book 'phoenix' has been re-fetched from db");
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc1->getId());
$blc1 = BookClubListPeer::doSelectOne($crit);
$this->assertNotNull($blc1, 'BookClubList 1 has been re-fetched from db');
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc2->getId());
$blc2 = BookClubListPeer::doSelectOne($crit);
$this->assertNotNull($blc2, 'BookClubList 2 has been re-fetched from db');
$relCount = $phoenix->countBookListRels();
$this->assertEquals(2, $relCount, "book 'phoenix' has 2 BookListRels");
$relCount = $blc1->countBookListRels();
$this->assertEquals(2, $relCount, 'BookClubList 1 has 2 BookListRels');
$relCount = $blc2->countBookListRels();
$this->assertEquals(1, $relCount, 'BookClubList 2 has 1 BookListRel');
// Cleanup (tests DELETE)
// ----------------------
// Removing books that were just created
// First finding book by PK (=$phoenix_id) ....
$hp = BookPeer::retrieveByPk($phoenix_id);
$this->assertNotNull($hp, 'Could find just-created book');
// Attempting to delete [multi-table] by found pk
$c = new Criteria();
$c->add(BookPeer::ID, $hp->getId());
// The only way for cascading to work currently
// is to specify the author_id and publisher_id (i.e. the fkeys
// have to be in the criteria).
$c->add(AuthorPeer::ID, $hp->getAuthor()->getId());
$c->add(PublisherPeer::ID, $hp->getPublisher()->getId());
$c->setSingleRecord(true);
BookPeer::doDelete($c);
// Checking to make sure correct records were removed.
$this->assertEquals(3, AuthorPeer::doCount(new Criteria()), 'Correct records were removed from author table');
$this->assertEquals(3, PublisherPeer::doCount(new Criteria()), 'Correct records were removed from publisher table');
$this->assertEquals(3, BookPeer::doCount(new Criteria()), 'Correct records were removed from book table');
// Attempting to delete books by complex criteria
$c = new Criteria();
$cn = $c->getNewCriterion(BookPeer::ISBN, "043935806X");
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0380977427"));
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0140422161"));
$c->add($cn);
BookPeer::doDelete($c);
// Attempting to delete book [id = $td_id]
$td->delete();
// Attempting to delete authors
AuthorPeer::doDelete($stephenson_id);
AuthorPeer::doDelete($byron_id);
$grass->delete();
// Attempting to delete publishers
PublisherPeer::doDelete($morrow_id);
PublisherPeer::doDelete($penguin_id);
$vintage->delete();
// These have to be deleted manually also since we have onDelete
// set to SETNULL in the foreign keys in book. Is this correct?
$rowling->delete();
$scholastic->delete();
$blc1->delete();
$blc2->delete();
$this->assertEquals(array(), AuthorPeer::doSelect(new Criteria()), 'no records in [author] table');
$this->assertEquals(array(), PublisherPeer::doSelect(new Criteria()), 'no records in [publisher] table');
$this->assertEquals(array(), BookPeer::doSelect(new Criteria()), 'no records in [book] table');
$this->assertEquals(array(), ReviewPeer::doSelect(new Criteria()), 'no records in [review] table');
$this->assertEquals(array(), MediaPeer::doSelect(new Criteria()), 'no records in [media] table');
$this->assertEquals(array(), BookClubListPeer::doSelect(new Criteria()), 'no records in [book_club_list] table');
$this->assertEquals(array(), BookListRelPeer::doSelect(new Criteria()), 'no records in [book_x_list] table');
}
示例3: delete
/**
* Removes this object from datastore and sets delete attribute.
*
* @param PropelPDO $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete(PropelPDO $con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($con === null) {
$con = Propel::getConnection(AuthorPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
$con->beginTransaction();
try {
$ret = $this->preDelete($con);
// symfony_behaviors behavior
foreach (sfMixer::getCallables('BaseAuthor:delete:pre') as $callable) {
if (call_user_func($callable, $this, $con)) {
$con->commit();
return;
}
}
if ($ret) {
AuthorPeer::doDelete($this, $con);
$this->postDelete($con);
// symfony_behaviors behavior
foreach (sfMixer::getCallables('BaseAuthor:delete:post') as $callable) {
call_user_func($callable, $this, $con);
}
$this->setDeleted(true);
$con->commit();
} else {
$con->commit();
}
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
示例4: Criteria
print "Attempting to delete books by complex criteria: ";
$c = new Criteria();
$cn = $c->getNewCriterion(BookPeer::ISBN, "043935806X");
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0380977427"));
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0140422161"));
$c->add($cn);
BookPeer::doDelete($c);
print boolTest(true);
print "Attempting to delete book [id = {$td_id}]: ";
$td->delete();
print boolTest(true);
print "Attempting to delete author [id = {$stephenson_id}]: ";
AuthorPeer::doDelete($stephenson_id);
print boolTest(true);
print "Attempting to delete author [id = {$byron_id}]: ";
AuthorPeer::doDelete($byron_id);
print boolTest(true);
print "Attempting to delete author [id = {$grass_id}]: ";
$grass->delete();
print boolTest(true);
print "Attempting to delete publisher [id = {$morrow_id}]: ";
PublisherPeer::doDelete($morrow_id);
print boolTest(true);
print "Attempting to delete publisher [id = {$penguin_id}]: ";
PublisherPeer::doDelete($penguin_id);
print boolTest(true);
print "Attempting to delete publisher [id = {$vintage_id}]: ";
$vintage->delete();
print boolTest(true);
// These have to be deleted manually also since we have onDelete
// set to SETNULL in the foreign keys in book. Is this correct?
示例5: testDoDelete_SetNull
/**
* Test that onDelete="SETNULL" is happening correctly (whether emulated or native).
*/
public function testDoDelete_SetNull()
{
// The 'author_id' column in 'book' table will be set to null when author is deleted.
// 1) Get an arbitrary book
$c = new Criteria();
$book = BookPeer::doSelectOne($c);
$bookId = $book->getId();
$authorId = $book->getAuthorId();
unset($book);
// 2) Delete the author for that book
AuthorPeer::doDelete($authorId);
// 3) Assert that the book.author_id column is now NULL
$book = BookPeer::retrieveByPK($bookId);
$this->assertNull($book->getAuthorId(), "Expect the book.author_id to be NULL after the author was removed.");
}
示例6: testSpeed
//.........这里部分代码省略.........
$ret = $bk2->validate();
// Now trying some more complex validation.
$auth1 = new Author();
$auth1->setFirstName("Hans");
// last name required; will fail
$bk1->setAuthor($auth1);
$rev1 = new Review();
$rev1->setReviewDate("08/09/2001");
// will fail: reviewed_by column required
$bk1->addReview($rev1);
$ret2 = $bk1->validate();
$bk2 = new Book();
$bk2->setTitle("12345678901");
// passes
$auth2 = new Author();
$auth2->setLastName("Blah");
//passes
$auth2->setEmail("some@body.com");
//passes
$auth2->setAge(50);
//passes
$bk2->setAuthor($auth2);
$rev2 = new Review();
$rev2->setReviewedBy("Me!");
// passes
$rev2->setStatus("new");
// passes
$bk2->addReview($rev2);
$ret3 = $bk2->validate();
// Testing doCount() functionality
// -------------------------------
$c = new Criteria();
$count = BookPeer::doCount($c);
// Testing many-to-many relationships
// ----------------------------------
// init book club list 1 with 2 books
$blc1 = new BookClubList();
$blc1->setGroupLeader("Crazyleggs");
$blc1->setTheme("Happiness");
$brel1 = new BookListRel();
$brel1->setBook($phoenix);
$brel2 = new BookListRel();
$brel2->setBook($dj);
$blc1->addBookListRel($brel1);
$blc1->addBookListRel($brel2);
$blc1->save();
// init book club list 2 with 1 book
$blc2 = new BookClubList();
$blc2->setGroupLeader("John Foo");
$blc2->setTheme("Default");
$brel3 = new BookListRel();
$brel3->setBook($phoenix);
$blc2->addBookListRel($brel3);
$blc2->save();
// re-fetch books and lists from db to be sure that nothing is cached
$crit = new Criteria();
$crit->add(BookPeer::ID, $phoenix->getId());
$phoenix = BookPeer::doSelectOne($crit);
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc1->getId());
$blc1 = BookClubListPeer::doSelectOne($crit);
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc2->getId());
$blc2 = BookClubListPeer::doSelectOne($crit);
$relCount = $phoenix->countBookListRels();
$relCount = $blc1->countBookListRels();
$relCount = $blc2->countBookListRels();
// Removing books that were just created
// -------------------------------------
$hp = BookPeer::retrieveByPk($phoenix_id);
$c = new Criteria();
$c->add(BookPeer::ID, $hp->getId());
// The only way for cascading to work currently
// is to specify the author_id and publisher_id (i.e. the fkeys
// have to be in the criteria).
$c->add(AuthorPeer::ID, $hp->getId());
$c->add(PublisherPeer::ID, $hp->getId());
$c->setSingleRecord(true);
BookPeer::doDelete($c);
// Attempting to delete books by complex criteria
$c = new Criteria();
$cn = $c->getNewCriterion(BookPeer::ISBN, "043935806X");
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0380977427"));
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0140422161"));
$c->add($cn);
BookPeer::doDelete($c);
$td->delete();
AuthorPeer::doDelete($stephenson_id);
AuthorPeer::doDelete($byron_id);
$grass->delete();
PublisherPeer::doDelete($morrow_id);
PublisherPeer::doDelete($penguin_id);
$vintage->delete();
// These have to be deleted manually also since we have onDelete
// set to SETNULL in the foreign keys in book. Is this correct?
$rowling->delete();
$scholastic->delete();
$blc1->delete();
$blc2->delete();
}
示例7: delete
/**
* Removes this object from datastore and sets delete attribute.
*
* @param PropelPDO $con
* @return void
* @throws PropelException
* @see BaseObject::setDeleted()
* @see BaseObject::isDeleted()
*/
public function delete(PropelPDO $con = null)
{
if ($this->isDeleted()) {
throw new PropelException("This object has already been deleted.");
}
if ($con === null) {
$con = Propel::getConnection(AuthorPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
$con->beginTransaction();
try {
$ret = $this->preDelete($con);
if ($ret) {
AuthorPeer::doDelete($this, $con);
$this->postDelete($con);
$this->setDeleted(true);
$con->commit();
} else {
$con->commit();
}
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}