renameAssociation() 공개 정적인 메소드

Facade method for AQueryWriter::renameAssociation()
public static renameAssociation ( string | array $from, string $to = NULL ) : void
$from string | array
$to string
리턴 void
예제 #1
0
 /**
  * Test prettier tables using via().
  */
 public function testViaPrettification()
 {
     R::nuke();
     R::renameAssociation('tbl_author_tbl_friend', 'tbl_author_friend');
     $author = R::xdispense(AUTHOR);
     $author->name = 'Mr. Quill';
     $friend = R::xdispense(FRIEND);
     $friend->name = 'Muse';
     $author->{FRIENDLIST}[] = $friend;
     $id = R::store($author);
     //print_r(R::inspect()); exit;
     $author = R::load(AUTHOR, $id);
     $tables = array_flip(R::inspect());
     asrt(isset($tables['tbl_author_friend']), TRUE);
     asrt(isset($tables['tbl_author_tbl_friend']), FALSE);
     asrt(count($author->{FRIENDLIST}), 1);
     AQueryWriter::clearRenames();
 }
예제 #2
0
 /**
  * test emulation via association renaming
  *
  * @return void
  */
 public function testAssociationRenaming()
 {
     list($p1, $p2, $p3) = R::dispense('painting', 3);
     list($m1, $m2, $m3) = R::dispense('museum', 3);
     $p1->name = 'painting1';
     $p2->name = 'painting2';
     $p3->name = 'painting3';
     $m1->thename = 'a';
     $m2->thename = 'b';
     $m3->thename = 'c';
     R::renameAssociation('museum_painting', 'exhibited');
     // Also test array syntax
     R::renameAssociation(array('museum_museum' => 'center'));
     $m1->link('center', array('name' => 'History Center'))->museum2 = $m2;
     $m1->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p3;
     $m2->link('exhibited', '{"from":"2014-07-03","til":"2014-10-02"}')->painting = $p3;
     $m3->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p1;
     $m2->link('exhibited', '{"from":"2014-02-01","til":"2014-07-02"}')->painting = $p2;
     R::storeAll(array($m1, $m2, $m3));
     list($m1, $m2, $m3) = array_values(R::findAll('museum', ' ORDER BY thename ASC'));
     asrt(count($m1->sharedMuseum), 1);
     asrt(count($m1->sharedPainting), 1);
     asrt(count($m2->sharedPainting), 2);
     asrt(count($m3->sharedPainting), 1);
     $p3 = reset($m1->sharedPainting);
     asrt(count($p3->ownExhibited), 2);
     asrt(count($m2->ownExhibited), 2);
     R::storeAll(array($m1, $m2, $m3));
     list($m1, $m2, $m3) = array_values(R::findAll('museum', ' ORDER BY thename ASC'));
     asrt(count($m1->sharedPainting), 1);
     asrt(count($m2->sharedPainting), 2);
     asrt(count($m3->sharedPainting), 1);
     $p3 = reset($m1->sharedPainting);
     asrt(count($p3->ownExhibited), 2);
     $paintings = $m2->sharedPainting;
     foreach ($paintings as $painting) {
         if ($painting->name === 'painting2') {
             pass();
             $paintingX = $painting;
         }
     }
     unset($m2->sharedPainting[$paintingX->id]);
     R::store($m2);
     $m2 = R::load('museum', $m2->id);
     asrt(count($m2->sharedPainting), 1);
     $left = reset($m2->sharedPainting);
     asrt($left->name, 'painting3');
     asrt(count($m2->ownExhibited), 1);
     $exhibition = reset($m2->ownExhibited);
     asrt($exhibition->from, '2014-07-03');
     asrt($exhibition->til, '2014-10-02');
 }