当前位置: 首页>>代码示例>>PHP>>正文


PHP Author::setBooks方法代码示例

本文整理汇总了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());
 }
开发者ID:ratibus,项目名称:Crew,代码行数:31,代码来源:GeneratedObjectTest.php

示例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());
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:36,代码来源:GeneratedObjectTest.php

示例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 =>
开发者ID:gries,项目名称:json-resolver,代码行数:31,代码来源:complex.php


注:本文中的Author::setBooks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。