/**
  * @rebuild false
  * @basedata false
  */
 public function testHasManyRelationCreate2()
 {
     $author = new \AuthorBooks\Model\Author();
     $ret = $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     ok($author->id);
     $this->assertResultSuccess($ret);
     // append items
     $author->addresses[] = array('address' => 'Harvard');
     $author->addresses[] = array('address' => 'Harvard II');
     is(2, $author->addresses->size(), 'just two item');
     $addresses = $author->addresses->items();
     ok($addresses);
     is('Harvard', $addresses[0]->address);
     $a = $addresses[0];
     ok($retAuthor = $a->author);
     ok($retAuthor->id);
     ok($retAuthor->name);
     is('Z', $retAuthor->name);
     $this->assertResultSuccess($author->delete());
 }
示例#2
0
 public function testHasManyRelationFetch()
 {
     $author = new \AuthorBooks\Model\Author();
     $ret = $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     $this->assertResultSuccess($ret);
     $address = new \AuthorBooks\Model\Address();
     $ret = $address->create(array('author_id' => $author->id, 'address' => 'Taiwan Taipei'));
     $this->assertResultSuccess($ret);
     $this->assertInstanceOf('LazyRecord\\BaseModel', $address->author);
     $this->assertEquals($author->id, $address->author->id);
     $ret = $address->create(array('author_id' => $author->id, 'address' => 'Taiwan Taipei II'));
     $this->assertResultSuccess($ret);
     // xxx: provide getAddresses() method generator
     $addresses = $author->addresses;
     $this->assertInstanceOf('LazyRecord\\BaseCollection', $addresses);
     $items = $addresses->items();
     $this->assertNotEmpty($items);
     $this->assertCount(2, $items);
 }
示例#3
0
 public function testHasManyRelationCreate()
 {
     $author = new \AuthorBooks\Model\Author();
     $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     ok($author->id);
     $address = $author->addresses->create(array('address' => 'farfaraway'));
     ok($address->id);
     ok($address->author_id);
     $this->assertEquals($author->id, $address->author_id);
     $this->assertEquals('farfaraway', $address->address);
     $address->delete();
     $author->delete();
 }