本文整理汇总了PHP中Propel\Tests\Bookstore\Author::setBooks方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::setBooks方法的具体用法?PHP Author::setBooks怎么用?PHP Author::setBooks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Tests\Bookstore\Author
的用法示例。
在下文中一共展示了Author::setBooks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetterOneToManyReplacesOldObjectsByNewObjects
public function testSetterOneToManyReplacesOldObjectsByNewObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$books = new ObjectCollection();
foreach (array('foo', 'bar') as $title) {
$b = new Book();
$b->setTitle($title);
$b->setISBN('FA404');
$books[] = $b;
}
$a = new Author();
$a->setFirstName('Chuck');
$a->setLastName('Norris');
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('foo', $books[0]->getTitle());
$this->assertEquals('bar', $books[1]->getTitle());
$books = new ObjectCollection();
foreach (array('bam', 'bom') as $title) {
$b = new Book();
$b->setTitle($title);
$b->setISBN('FA404');
$books[] = $b;
}
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('bam', $books[0]->getTitle());
$this->assertEquals('bom', $books[1]->getTitle());
$this->assertEquals(1, AuthorQuery::create()->count());
// the replaced book are still there because the PK is not required
$this->assertEquals(4, BookQuery::create()->count());
}
示例2: testSetterOneToManyReplacesOldObjectsByNewObjects
public function testSetterOneToManyReplacesOldObjectsByNewObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$books = new ObjectCollection();
foreach (array('foo', 'bar') as $title) {
$b = new Book();
$b->setTitle($title);
$books[] = $b;
}
$a = new Author();
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('foo', $books[0]->getTitle());
$this->assertEquals('bar', $books[1]->getTitle());
$books = new ObjectCollection();
foreach (array('bam', 'bom') as $title) {
$b = new Book();
$b->setTitle($title);
$books[] = $b;
}
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('bam', $books[0]->getTitle());
$this->assertEquals('bom', $books[1]->getTitle());
$this->assertEquals(1, AuthorQuery::create()->count());
$this->assertEquals(2, BookQuery::create()->count());
}