本文整理汇总了PHP中Library::constructByKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Library::constructByKey方法的具体用法?PHP Library::constructByKey怎么用?PHP Library::constructByKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Library
的用法示例。
在下文中一共展示了Library::constructByKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testManyToMany
public function testManyToMany()
{
$library = new Library();
$library->setName('Travis County Reader');
$library->save();
$library2 = new Library();
$library2->setName('LBJ Center');
$library2->save();
$author = new Author();
$author->setName('Haruki Murakami');
$book = new Book();
$book->setTitle('Norwegian Wood');
$book->save();
$book2 = new Book();
$book2->setTitle('Kafka on the Shore');
$book2->save();
$author->addBook($book);
$author->addBook($book2);
$author->save();
$book2library = new Book2library();
$book2library->setBookId($book->getBookId());
$book2library->setLibraryId($library->getLibraryId());
$book2library->save();
$book2library2 = new Book2library();
$book2library2->setBookId($book2->getBookId());
$book2library2->setLibraryId($library->getLibraryId());
$book2library2->save();
$book2library3 = new Book2library();
$book2library3->setBookId($book->getBookId());
$book2library3->setLibraryId($library2->getLibraryId());
$book2library3->save();
$book2library4 = new Book2library();
$book2library4->setBookId($book2->getBookId());
$book2library4->setLibraryId($library2->getLibraryId());
$book2library4->save();
// now both books should be in both libraries
$sameLibrary = Library::constructByKey($library->getLibraryId());
$bookJoinsInTravis = $sameLibrary->getBook2library_Collection();
// $this->dump($bookJoinsInTravis);
$this->assertEqual(count($bookJoinsInTravis), 2);
// This test is similar to the 4 that are commented out below, but this shows what is different
// AND it ignores the creation_datetime and last_modified_datetime differences b/c they are
// intentionally not autoloaded after a save. Just manually call load() after save if you want
// to get the updated data.
$mismatches = $this->getFieldMismatches($bookJoinsInTravis->getPosition(0)->getBook_Object(), $book);
// Unset mistmatches that we know to be intentional
if (isset($mismatches['creation_datetime'])) {
unset($mismatches['creation_datetime']);
}
if (isset($mismatches['last_modified_datetime'])) {
unset($mismatches['last_modified_datetime']);
}
$this->assertTrue(empty($mismatches), implode("\n", $mismatches));
// these fail because the $book and $book2 don't have some default values set after save like creation_datetime
// (which is intentional; call load() after save if you want to get the updated data.)
// $this->assertIdentical($bookJoinsInTravis->getPosition(0)->getBook_Object(), $book);
// $this->assertIdentical($bookJoinsInTravis->getPosition(1)->getBook_Object(), $book2);
$this->assertEqual($bookJoinsInTravis->getPosition(0)->getBook_Object()->getBookId(), $book->getBookId());
$this->assertEqual($bookJoinsInTravis->getPosition(1)->getBook_Object()->getBookId(), $book2->getBookId());
$sameLibrary2 = Library::constructByKey($library2->getLibraryId());
$bookJoinsInLbj = $sameLibrary2->getBook2library_Collection();
$this->assertEqual(count($bookJoinsInLbj), 2);
// these fail because the $book and $book2 don't have some default values set after save like creation_datetime
// (which is intentional; call load() after save if you want to get the updated data.)
// $this->assertIdentical($bookJoinsInLbj->getPosition(0)->getBook_Object(), $book);
// $this->assertIdentical($bookJoinsInLbj->getPosition(1)->getBook_Object(), $book2);
$this->assertEqual($bookJoinsInLbj->getPosition(0)->getBook_Object()->getBookId(), $book->getBookId());
$this->assertEqual($bookJoinsInLbj->getPosition(1)->getBook_Object()->getBookId(), $book2->getBookId());
}
示例2: loadLibrary_Object
public function loadLibrary_Object()
{
$this->setLibrary_Object(Library::constructByKey($this->getLibraryId()));
}