本文整理汇总了PHP中Propel\Runtime\ActiveQuery\Criteria::setSingleRecord方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::setSingleRecord方法的具体用法?PHP Criteria::setSingleRecord怎么用?PHP Criteria::setSingleRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\ActiveQuery\Criteria
的用法示例。
在下文中一共展示了Criteria::setSingleRecord方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDoDelete_MultiTable
/**
* Test ability to delete multiple rows via single Criteria object.
*/
public function testDoDelete_MultiTable()
{
$hp = BookQuery::create()->filterByTitle("Harry Potter and the Order of the Phoenix")->findOne();
// print "Attempting to delete [multi-table] by found pk: ";
$c = new Criteria();
$c->add(BookTableMap::ID, $hp->getId());
// The only way for multi-delete to work currently
// is to specify the author_id and publisher_id (i.e. the fkeys
// have to be in the criteria).
$c->add(AuthorTableMap::ID, $hp->getAuthorId());
$c->add(PublisherTableMap::ID, $hp->getPublisherId());
$c->setSingleRecord(true);
BookTableMap::doDelete($c);
// check to make sure the right # of records was removed
$this->assertCount(3, AuthorQuery::create()->find(), "Expected 3 authors after deleting.");
$this->assertCount(3, PublisherQuery::create()->find(), "Expected 3 publishers after deleting.");
$this->assertCount(3, BookQuery::create()->find(), "Expected 3 books after deleting.");
}
示例2: testScenarioUsingQuery
//.........这里部分代码省略.........
$this->assertEquals(file_get_contents($clob_path), (string) $m1_lookup->getExcerpt(), 'CLOB was correctly updated');
// now update the BLOB column and save it & check the results
$m1_lookup->setCoverImage(file_get_contents($blob2_path));
$m1_lookup->save();
$m2_lookup = MediaQuery::create()->findPk($m1_id);
$this->assertNotNull($m2_lookup, 'Can find just-created media item');
$this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2_lookup->getCoverImage())), 'BLOB was correctly overwritten');
// Testing count() functionality
// -------------------------------
$records = BookQuery::create()->find();
$count = BookQuery::create()->count();
$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(BookTableMap::COL_ID, $phoenix->getId());
$phoenix = BookQuery::create(null, $crit)->findOne();
$this->assertNotNull($phoenix, "book 'phoenix' has been re-fetched from db");
$crit = new Criteria();
$crit->add(BookClubListTableMap::COL_ID, $blc1->getId());
$blc1 = BookClubListQuery::create(null, $crit)->findOne();
$this->assertNotNull($blc1, 'BookClubList 1 has been re-fetched from db');
$crit = new Criteria();
$crit->add(BookClubListTableMap::COL_ID, $blc2->getId());
$blc2 = BookClubListQuery::create(null, $crit)->findOne();
$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 = BookQuery::create()->findPk($phoenix_id);
$this->assertNotNull($hp, 'Could find just-created book');
// Attempting to delete [multi-table] by found pk
$c = new Criteria();
$c->add(BookTableMap::COL_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(AuthorTableMap::COL_ID, $hp->getAuthor()->getId());
$c->add(PublisherTableMap::COL_ID, $hp->getPublisher()->getId());
$c->setSingleRecord(true);
BookTableMap::doDelete($c);
// Checking to make sure correct records were removed.
$this->assertEquals(3, AuthorQuery::create()->count(), 'Correct records were removed from author table');
$this->assertEquals(3, PublisherQuery::create()->count(), 'Correct records were removed from publisher table');
$this->assertEquals(3, BookQuery::create()->count(), 'Correct records were removed from book table');
// Attempting to delete books by complex criteria
BookQuery::create()->filterByISBN("043935806X")->_or()->where('Book.ISBN = ?', "0380977427")->_or()->where('Book.ISBN = ?', "0140422161")->delete();
// Attempting to delete book [id = $td_id]
$td->delete();
// Attempting to delete authors
AuthorQuery::create()->filterById($stephenson_id)->delete();
AuthorQuery::create()->filterById($byron_id)->delete();
$grass->delete();
// Attempting to delete publishers
PublisherQuery::create()->filterById($morrow_id)->delete();
PublisherQuery::create()->filterById($penguin_id)->delete();
$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->assertCount(0, AuthorQuery::create()->find(), 'no records in [author] table');
$this->assertCount(0, PublisherQuery::create()->find(), 'no records in [publisher] table');
$this->assertCount(0, BookQuery::create()->find(), 'no records in [book] table');
$this->assertCount(0, ReviewQuery::create()->find(), 'no records in [review] table');
$this->assertCount(0, MediaQuery::create()->find(), 'no records in [media] table');
$this->assertCount(0, BookClubListQuery::create()->find(), 'no records in [book_club_list] table');
$this->assertCount(0, BookListRelQuery::create()->find(), 'no records in [book_x_list] table');
}