本文整理汇总了PHP中Propel\Tests\Bookstore\Author::addBook方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::addBook方法的具体用法?PHP Author::addBook怎么用?PHP Author::addBook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Tests\Bookstore\Author
的用法示例。
在下文中一共展示了Author::addBook方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSerializeObjectWithCollections
public function testSerializeObjectWithCollections()
{
$book1 = new Book();
$book1->setTitle('Foo5');
$book1->setISBN('1234');
$book2 = new Book();
$book2->setTitle('Foo6');
$book2->setISBN('1234');
$author = new Author();
$author->setFirstName('JAne');
$author->addBook($book1);
$author->addBook($book2);
$author->save();
$a = clone $author;
$sa = serialize($a);
$author->clearAllReferences();
$this->assertEquals($author, unserialize($sa));
}
示例2: setUp
public function setUp()
{
parent::setUp();
$a = new Author();
$a->setFirstName("Douglas");
$a->setLastName("Adams");
$b1 = new Book();
$b1->setTitle("The Hitchhikers Guide To The Galaxy");
$a->addBook($b1);
$b2 = new Book();
$b2->setTitle("The Restaurant At The End Of The Universe");
$a->addBook($b2);
$a->save();
$this->author = $a;
$this->books = array($b1, $b2);
Propel::enableInstancePooling();
// Clear author instance pool so the object would be fetched from the database
AuthorTableMap::clearInstancePool();
}
示例3: testRefFKAddReturnsCurrentObject
public function testRefFKAddReturnsCurrentObject()
{
$author = new Author();
$author->setFirstName('Leo');
$ret = $author->addBook(new Book());
$this->assertSame($author, $ret);
}
示例4: testToArrayIncludesForeignReferrers
public function testToArrayIncludesForeignReferrers()
{
$a1 = new Author();
$a1->setFirstName('Leo');
$a1->setLastName('Tolstoi');
$arr = $a1->toArray(BasePeer::TYPE_PHPNAME, null, array(), true);
$this->assertFalse(array_key_exists('Books', $arr));
$b1 = new Book();
$b1->setTitle('War and Peace');
$b2 = new Book();
$b2->setTitle('Anna Karenina');
$a1->addBook($b1);
$a1->addBook($b2);
$arr = $a1->toArray(BasePeer::TYPE_PHPNAME, null, array(), true);
$this->assertTrue(array_key_exists('Books', $arr));
$this->assertEquals(2, count($arr['Books']));
$this->assertEquals('War and Peace', $arr['Books']['Book_0']['Title']);
$this->assertEquals('Anna Karenina', $arr['Books']['Book_1']['Title']);
$this->assertEquals('*RECURSION*', $arr['Books']['Book_0']['Author']);
}
示例5: testFindOneWithEmptyLeftJoinOneToMany
public function testFindOneWithEmptyLeftJoinOneToMany()
{
// non-empty relation
$a1 = new Author();
$a1->setFirstName('Foo');
$a1->setLastName('Bar');
$b1 = new Book();
$b1->setTitle('Foo1');
$b1->setISBN('FA404-1');
$a1->addBook($b1);
$b2 = new Book();
$b2->setTitle('Foo2');
$b2->setISBN('FA404-2');
$a1->addBook($b2);
$a1->save();
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$author = AuthorQuery::create()->filterByFirstName('Foo')->leftJoinWith('Propel\\Tests\\Bookstore\\Author.Book')->find($con)->get(0);
$count = $con->getQueryCount();
$books = $author->getBooks(null, $con);
$this->assertEquals(2, $books->count());
$this->assertEquals($count, $con->getQueryCount());
// empty relation
$a2 = new Author();
$a2->setFirstName('Bar');
$a2->setLastName('Bar');
$a2->save();
$author = AuthorQuery::create()->filterByFirstName('Bar')->leftJoinWith('Propel\\Tests\\Bookstore\\Author.Book')->find($con)->get(0);
$count = $con->getQueryCount();
$books = $author->getBooks(null, $con);
$this->assertEquals(0, $books->count());
$this->assertEquals($count, $con->getQueryCount());
}
示例6: testSavedObjectCreatesDifferentHashForIdenticalObjects
/**
* Primary key should differ
*/
public function testSavedObjectCreatesDifferentHashForIdenticalObjects()
{
$book1 = new Book();
$book1->setTitle('Foo5');
$book1->setISBN('1234');
$author1 = new Author();
$author1->setFirstName('JAne');
$author1->setLastName('JAne');
$author1->addBook($book1);
$author1->save();
$author2 = new Author();
$author2->setFirstName('JAne');
$author2->setLastName('JAne');
$author2->addBook($book1);
$author2->save();
$this->assertNotEquals($author1->hashCode(), $author2->hashCode());
}
示例7: testNewObjectsGetLostOnJoin
public function testNewObjectsGetLostOnJoin()
{
/* While testNewObjectsAvailableWhenSaveNotCalled passed as of
revision 851, in this case we call getBooksJoinPublisher() instead
of just getBooks(). get...Join...() does not contain the check whether
the current object is new, it will always consult the DB and lose the
new objects entirely. Thus the test fails. (At least for Propel 1.2 ?!?) */
$this->markTestSkipped();
$a = new Author();
$a->setFirstName("Douglas");
$a->setLastName("Adams");
$p = new Publisher();
$p->setName('Pan Books Ltd.');
$b1 = new Book();
$b1->setTitle("The Hitchhikers Guide To The Galaxy");
$b1->setISBN('FA404-1');
$b1->setPublisher($p);
// uh... did not check that :^)
$a->addBook($b1);
$b2 = new Book();
$b2->setTitle("The Restaurant At The End Of The Universe");
$b1->setISBN('FA404-2');
$b2->setPublisher($p);
$a->addBook($b2);
$books = $a->getBooksJoinPublisher();
$this->assertEquals(2, count($books));
$this->assertContains($b1, $books);
$this->assertContains($b2, $books);
$a->save();
$this->assertFalse($b1->isNew());
$this->assertFalse($b2->isNew());
}
示例8: testRemoveObjectOneToMany
public function testRemoveObjectOneToMany()
{
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$book = new Book();
$book->setISBN('012345');
$book->setTitle('Propel Book');
$book2 = new Book();
$book2->setISBN('6789');
$book2->setTitle('Propel2 Book');
$author = new Author();
$author->setFirstName('François');
$author->setLastName('Z');
$author->addBook($book);
$author->addBook($book2);
$this->assertCount(2, $author->getBooks());
$author->removeBook($book);
$books = $author->getBooks();
$this->assertCount(1, $books);
$this->assertEquals('Propel2 Book', $books->getFirst()->getTitle());
$author->save();
$book->save();
$book2->save();
$this->assertEquals(2, BookQuery::create()->count(), 'Two Book');
$this->assertEquals(1, AuthorQuery::create()->count(), 'One Author');
$this->assertEquals(1, BookQuery::create()->filterByAuthor($author)->count());
$author->addBook($book);
$author->save();
$this->assertEquals(2, BookQuery::create()->filterByAuthor($author)->count());
$author->removeBook($book2);
$author->save();
$this->assertEquals(1, BookQuery::create()->filterByAuthor($author)->count());
$this->assertEquals(2, BookQuery::create()->count(), 'Two Book because FK is not required so book is not delete when removed from author\'s book collection');
}
示例9: testFindOneWithEmptyLeftJoinOneToMany
public function testFindOneWithEmptyLeftJoinOneToMany()
{
// non-empty relation
$a1 = new Author();
$a1->setFirstName('Foo');
$b1 = new Book();
$b1->setTitle('Foo1');
$a1->addBook($b1);
$b2 = new Book();
$b2->setTitle('Foo2');
$a1->addBook($b2);
$a1->save();
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
$author = AuthorQuery::create()->filterByFirstName('Foo')->leftJoinWith('Author.Book')->findOne($con);
$count = $con->getQueryCount();
$books = $author->getBooks(null, $con);
$this->assertEquals(2, $books->count());
$this->assertEquals($count, $con->getQueryCount());
// empty relation
$a2 = new Author();
$a2->setFirstName('Bar');
$a2->save();
$author = AuthorQuery::create()->filterByFirstName('Bar')->leftJoinWith('Author.Book')->findOne($con);
$count = $con->getQueryCount();
$books = $author->getBooks(null, $con);
$this->assertEquals(0, $books->count());
$this->assertEquals($count, $con->getQueryCount());
}