本文整理汇总了PHP中Author::setBooks方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::setBooks方法的具体用法?PHP Author::setBooks怎么用?PHP Author::setBooks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Author
的用法示例。
在下文中一共展示了Author::setBooks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetterOneToManyReplacesOldObjectsByNewObjects
public function testSetterOneToManyReplacesOldObjectsByNewObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$books = new PropelObjectCollection();
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 PropelObjectCollection();
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());
}
示例2: testSetterOneToManyReplacesOldObjectsByNewObjects
public function testSetterOneToManyReplacesOldObjectsByNewObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
$books = new PropelObjectCollection();
foreach (array('foo', 'bar') as $title) {
$b = new Book();
$b->setTitle($title);
$b->setIsbn('12354');
$books[] = $b;
}
$a = new Author();
$a->setFirstName('Foo');
$a->setLastName('Bar');
$a->setBooks($books);
$a->save();
$books = $a->getBooks();
$this->assertEquals('foo', $books[0]->getTitle());
$this->assertEquals('bar', $books[1]->getTitle());
$books = new PropelObjectCollection();
foreach (array('bam', 'bom') as $title) {
$b = new Book();
$b->setTitle($title);
$b->setIsbn('1235');
$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());
}
示例3: JsonResolver
<?php
use Gries\JsonObjectResolver\JsonResolver;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/Author.php';
require_once __DIR__ . '/Book.php';
$book = new \Book();
$book->setTitle('test-title-1');
$book2 = new \Book();
$book2->setTitle('test-title-2');
$author = new \Author();
$author->setName('test-author');
$author->setBooks([$book, $book2]);
$resolver = new JsonResolver();
$json = $resolver->encode($author);
$decodedAuthor = $resolver->decode($json);
var_dump($author);
var_dump($decodedAuthor);
//class Author#4 (2) {
// protected $name =>
// string(11) "test-author"
// protected $books =>
// array(2) {
// [0] =>
// class Book#2 (1) {
// protected $title =>
// string(12) "test-title-1"
// }
// [1] =>
// class Book#3 (1) {
// protected $title =>