本文整理汇总了PHP中Propel\Tests\Bookstore\Book::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::save方法的具体用法?PHP Book::save怎么用?PHP Book::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Tests\Bookstore\Book
的用法示例。
在下文中一共展示了Book::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFormatALotOfResults
public function testFormatALotOfResults()
{
$nbBooks = 50;
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
Propel::disableInstancePooling();
$book = new Book();
for ($i = 0; $i < $nbBooks; $i++) {
$book->clear();
$book->setTitle('BookTest' . $i);
$book->save($con);
}
$stmt = $con->query('SELECT * FROM book');
$formatter = new PropelOnDemandFormatter();
$formatter->init(new ModelCriteria('bookstore', 'Book'));
$books = $formatter->format($stmt);
$this->assertTrue($books instanceof PropelOnDemandCollection, 'PropelOnDemandFormatter::format() returns a PropelOnDemandCollection');
$this->assertEquals($nbBooks, count($books), 'PropelOnDemandFormatter::format() returns a collection that counts as many rows as the results in the query');
$i = 0;
foreach ($books as $book) {
$this->assertTrue($book instanceof Book, 'PropelOnDemandFormatter::format() returns a collection of Model objects');
$this->assertEquals('BookTest' . $i, $book->getTitle(), 'PropelOnDemandFormatter::format() returns the model objects matching the query');
$i++;
}
Propel::enableInstancePooling();
}
示例2: testSerializeObjectWithRelations
public function testSerializeObjectWithRelations()
{
$author = new Author();
$author->setFirstName('John');
$book = new Book();
$book->setTitle('Foo4');
$book->setISBN('1234');
$book->setAuthor($author);
$book->save();
$b = clone $book;
$sb = serialize($b);
$book->clearAllReferences();
$this->assertEquals($book, unserialize($sb));
}
示例3: setUp
protected function setUp()
{
parent::setUp();
BookstoreDataPopulator::populate();
$cr = new Criteria();
$cr->add(AuthorPeer::LAST_NAME, "Rowling");
$cr->add(AuthorPeer::FIRST_NAME, "J.K.");
$rowling = AuthorPeer::doSelectOne($cr);
$this->authorId = $rowling->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Philosopher's Stone");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Chamber of Secrets");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Prisoner of Azkaban");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Goblet of Fire");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Half-Blood Prince");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Deathly Hallows");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
}
示例4: testGetPrimaryKeys
public function testGetPrimaryKeys()
{
$books = new ObjectCollection();
$books->setModel('\\Propel\\Tests\\Bookstore\\Book');
for ($i = 0; $i < 4; $i++) {
$book = new Book();
$book->setTitle('Title' . $i);
$book->save($this->con);
$books[] = $book;
}
$pks = $books->getPrimaryKeys();
$this->assertEquals(4, count($pks));
$keys = array('\\Propel\\Tests\\Bookstore\\Book_0', '\\Propel\\Tests\\Bookstore\\Book_1', '\\Propel\\Tests\\Bookstore\\Book_2', '\\Propel\\Tests\\Bookstore\\Book_3');
$this->assertEquals($keys, array_keys($pks));
$pks = $books->getPrimaryKeys(false);
$keys = array(0, 1, 2, 3);
$this->assertEquals($keys, array_keys($pks));
foreach ($pks as $key => $value) {
$this->assertEquals($books[$key]->getPrimaryKey(), $value);
}
}
示例5: testUtf8
public function testUtf8()
{
$this->markTestSkipped('Skipped because of weird behavior on some platforms');
$db = Propel::getServiceContainer()->getAdapter(BookPeer::DATABASE_NAME);
$title = "Смерть на брудершафт. Младенец и черт";
// 1234567890123456789012345678901234567
// 1 2 3
$a = new Author();
$a->setFirstName("Б.");
$a->setLastName("АКУНИН");
$p = new Publisher();
$p->setName("Детектив российский, остросюжетная проза");
$b = new Book();
$b->setTitle($title);
$b->setISBN("B-59246");
$b->setAuthor($a);
$b->setPublisher($p);
$b->save();
$b->reload();
$this->assertEquals(37, iconv_strlen($b->getTitle(), 'utf-8'), "Expected 37 characters (not bytes) in title.");
$this->assertTrue(strlen($b->getTitle()) > iconv_strlen($b->getTitle(), 'utf-8'), "Expected more bytes than characters in title.");
}
示例6: testGroupByArray
public function testGroupByArray()
{
$stephenson = new Author();
$stephenson->setFirstName("Neal");
$stephenson->setLastName("Stephenson");
$stephenson->save();
$byron = new Author();
$byron->setFirstName("George");
$byron->setLastName("Byron");
$byron->save();
$phoenix = new Book();
$phoenix->setTitle("Harry Potter and the Order of the Phoenix");
$phoenix->setISBN("043935806X");
$phoenix->setAuthor($stephenson);
$phoenix->save();
$qs = new Book();
$qs->setISBN("0380977427");
$qs->setTitle("Quicksilver");
$qs->setAuthor($stephenson);
$qs->save();
$dj = new Book();
$dj->setISBN("0140422161");
$dj->setTitle("Don Juan");
$dj->setAuthor($stephenson);
$dj->save();
$td = new Book();
$td->setISBN("067972575X");
$td->setTitle("The Tin Drum");
$td->setAuthor($byron);
$td->save();
$authors = AuthorQuery::create()->leftJoinBook()->select(array('FirstName', 'LastName'))->withColumn('COUNT(Book.Id)', 'nbBooks')->groupBy(array('FirstName', 'LastName'))->orderByLastName()->find();
$expectedSql = 'SELECT COUNT(book.id) AS nbBooks, author.first_name AS "FirstName", author.last_name AS "LastName" FROM author LEFT JOIN book ON (author.id=book.author_id) GROUP BY author.first_name,author.last_name ORDER BY author.last_name ASC';
$this->assertEquals($expectedSql, $this->con->getLastExecutedQuery());
$this->assertEquals(2, count($authors));
$this->assertEquals('George', $authors[0]['FirstName']);
$this->assertEquals(1, $authors[0]['nbBooks']);
$this->assertEquals('Neal', $authors[1]['FirstName']);
$this->assertEquals(3, $authors[1]['nbBooks']);
}
示例7: testSetterCollectionWithExistingObjects
public function testSetterCollectionWithExistingObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
BookClubListQuery::create()->deleteAll();
BookListRelQuery::create()->deleteAll();
for ($i = 0; $i < 3; $i++) {
$b = new Book();
$b->setTitle('Book ' . $i);
$b->save();
}
BookPeer::clearInstancePool();
$books = BookQuery::create()->find();
$bookClubList = new BookClubList();
$bookClubList->setBooks($books);
$bookClubList->save();
$this->assertEquals(3, count($bookClubList->getBooks()));
$this->assertEquals(3, BookQuery::create()->count());
$this->assertEquals(1, BookClubListQuery::create()->count());
$this->assertEquals(3, BookListRelQuery::create()->count());
$i = 0;
foreach ($bookClubList->getBooks() as $book) {
$this->assertEquals('Book ' . $i++, $book->getTitle());
}
}
示例8: testScenarioUsingQuery
public function testScenarioUsingQuery()
{
// Add publisher records
// ---------------------
try {
$scholastic = new Publisher();
$scholastic->setName("Scholastic");
// do not save, will do later to test cascade
$morrow = new Publisher();
$morrow->setName("William Morrow");
$morrow->save();
$morrow_id = $morrow->getId();
$penguin = new Publisher();
$penguin->setName("Penguin");
$penguin->save();
$penguin_id = $penguin->getId();
$vintage = new Publisher();
$vintage->setName("Vintage");
$vintage->save();
$vintage_id = $vintage->getId();
$this->assertTrue(true, 'Save Publisher records');
} catch (Exception $e) {
$this->fail('Save publisher records');
}
// Add author records
// ------------------
try {
$rowling = new Author();
$rowling->setFirstName("J.K.");
$rowling->setLastName("Rowling");
// do not save, will do later to test cascade
$stephenson = new Author();
$stephenson->setFirstName("Neal");
$stephenson->setLastName("Stephenson");
$stephenson->save();
$stephenson_id = $stephenson->getId();
$byron = new Author();
$byron->setFirstName("George");
$byron->setLastName("Byron");
$byron->save();
$byron_id = $byron->getId();
$grass = new Author();
$grass->setFirstName("Gunter");
$grass->setLastName("Grass");
$grass->save();
$grass_id = $grass->getId();
$this->assertTrue(true, 'Save Author records');
} catch (Exception $e) {
$this->fail('Save Author records');
}
// Add book records
// ----------------
try {
$phoenix = new Book();
$phoenix->setTitle("Harry Potter and the Order of the Phoenix");
$phoenix->setISBN("043935806X");
$phoenix->setAuthor($rowling);
$phoenix->setPublisher($scholastic);
$phoenix->save();
$phoenix_id = $phoenix->getId();
$this->assertFalse($rowling->isNew(), 'saving book also saves related author');
$this->assertFalse($scholastic->isNew(), 'saving book also saves related publisher');
$qs = new Book();
$qs->setISBN("0380977427");
$qs->setTitle("Quicksilver");
$qs->setAuthor($stephenson);
$qs->setPublisher($morrow);
$qs->save();
$qs_id = $qs->getId();
$dj = new Book();
$dj->setISBN("0140422161");
$dj->setTitle("Don Juan");
$dj->setAuthor($byron);
$dj->setPublisher($penguin);
$dj->save();
$dj_id = $qs->getId();
$td = new Book();
$td->setISBN("067972575X");
$td->setTitle("The Tin Drum");
$td->setAuthor($grass);
$td->setPublisher($vintage);
$td->save();
$td_id = $td->getId();
$this->assertTrue(true, 'Save Book records');
} catch (Exception $e) {
$this->fail('Save Author records');
}
// Add review records
// ------------------
try {
$r1 = new Review();
$r1->setBook($phoenix);
$r1->setReviewedBy("Washington Post");
$r1->setRecommended(true);
$r1->setReviewDate(time());
$r1->save();
$r1_id = $r1->getId();
$r2 = new Review();
$r2->setBook($phoenix);
$r2->setReviewedBy("New York Times");
//.........这里部分代码省略.........
示例9: testFindOneWithOneToManyCustomOrder
public function testFindOneWithOneToManyCustomOrder()
{
$author1 = new Author();
$author1->setFirstName('AA');
$author2 = new Author();
$author2->setFirstName('BB');
$book1 = new Book();
$book1->setTitle('Aaa');
$book1->setAuthor($author1);
$book1->save();
$book2 = new Book();
$book2->setTitle('Bbb');
$book2->setAuthor($author2);
$book2->save();
$book3 = new Book();
$book3->setTitle('Ccc');
$book3->setAuthor($author1);
$book3->save();
$authors = AuthorQuery::create()->setFormatter(ModelCriteria::FORMAT_ARRAY)->leftJoin('Propel\\Tests\\Bookstore\\Author.Book')->orderBy('Book.Title')->with('Book')->find();
$this->assertEquals(2, count($authors), 'with() used on a many-to-many doesn\'t change the main object count');
}
示例10: testFindPkDoesNotCallPreSelectWhenUsingInstancePool
public function testFindPkDoesNotCallPreSelectWhenUsingInstancePool()
{
$b = new Book();
$b->setTitle('foo');
$b->setISBN('FA404');
$b->save();
$q = new mySecondBookQuery();
$this->assertFalse($q::$preSelectWasCalled);
$q->findPk($b->getId());
$this->assertFalse($q::$preSelectWasCalled);
}
示例11: testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins
public function testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins()
{
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
BookOpinionTableMap::clearInstancePool();
BookReaderTableMap::clearInstancePool();
$freud = new Author();
$freud->setFirstName("Sigmund");
$freud->setLastName("Freud");
$freud->save($this->con);
$publisher = new Publisher();
$publisher->setName('Psycho Books');
$publisher->save();
$book = new Book();
$book->setAuthor($freud);
$book->setTitle('Weirdness');
$book->setIsbn('abc123456');
$book->setPrice('14.99');
$book->setPublisher($publisher);
$book->save();
$query = BookQuery::create()->filterByTitle('Weirdness')->innerJoinAuthor()->useBookOpinionQuery(null, Criteria::LEFT_JOIN)->leftJoinBookReader()->endUse()->with('Author')->with('BookOpinion')->with('BookReader');
$books = $query->find($this->con)->get(0);
$this->assertEquals(0, count($books->getBookOpinions()));
}
示例12: testSearchMatchesSimilarObjects
public function testSearchMatchesSimilarObjects()
{
$col = new ObjectCollection();
$b1 = new Book();
$b1->setTitle('Bar');
$b1->setISBN('012345');
$b1->save();
$b2 = clone $b1;
$this->assertFalse($col->search($b1), 'search() returns false on an empty collection');
$col = new ObjectCollection(array($b1));
$this->assertTrue(0 === $col->search($b1));
$this->assertTrue(0 === $col->search($b2));
}
示例13: testDoCountJoin
/**
* Test doCountJoin*() methods.
*/
public function testDoCountJoin()
{
BookPeer::doDeleteAll();
for ($i = 0; $i < 25; $i++) {
$b = new Book();
$b->setTitle("Book {$i}");
$b->setISBN("ISBN {$i}");
$b->save();
}
$c = new Criteria();
$totalCount = BookPeer::doCount($c);
$this->assertEquals($totalCount, BookPeer::doCountJoinAuthor($c));
$this->assertEquals($totalCount, BookPeer::doCountJoinPublisher($c));
}
示例14: testFindOneOrCreateMakesOneQueryWhenRecordExists
public function testFindOneOrCreateMakesOneQueryWhenRecordExists()
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
BookQuery::create()->deleteAll($con);
$book = new Book();
$book->setTitle('Title');
$book->setISBN('FA404');
$book->setPrice(125);
$book->save($con);
$count = $con->getQueryCount();
$book = BookQuery::create('b')->filterByPrice(125)->findOneOrCreate($con);
$this->assertEquals($count + 1, $con->getQueryCount(), 'findOneOrCreate() makes only a single query when the record exists');
}
示例15: testMultiColFk
/**
* Testing foreign keys with multiple referrer columns.
* @link http://propel.phpdb.org/trac/ticket/606
*/
public function testMultiColFk()
{
$con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
ReaderFavoritePeer::doDeleteAll();
$b1 = new Book();
$b1->setTitle("Book1");
$b1->setISBN("ISBN-1");
$b1->save();
$r1 = new BookReader();
$r1->setName("Me");
$r1->save();
$bo1 = new BookOpinion();
$bo1->setBookId($b1->getId());
$bo1->setReaderId($r1->getId());
$bo1->setRating(9);
$bo1->setRecommendToFriend(true);
$bo1->save();
$rf1 = new ReaderFavorite();
$rf1->setReaderId($r1->getId());
$rf1->setBookId($b1->getId());
$rf1->save();
$c = new Criteria(ReaderFavoritePeer::DATABASE_NAME);
$c->add(ReaderFavoritePeer::BOOK_ID, $b1->getId());
$c->add(ReaderFavoritePeer::READER_ID, $r1->getId());
$results = ReaderFavoritePeer::doSelectJoinBookOpinion($c);
$this->assertEquals(1, count($results), "Expected 1 result");
}