public function testTraversalWithAlias()
{
R::nuke();
$book = R::dispense('book');
$cats = R::dispense('category', 3);
$cats[0]->gname = 'SF';
$cats[1]->gname = 'Fantasy';
$cats[2]->gname = 'Horror';
$book->genre = $cats[0];
$book->name = 'Space Story';
$cats[0]->genre = $cats[1];
$cats[2]->genre = $cats[1];
R::store($book);
$book2 = R::dispense('book');
$book2->genre = $cats[2];
$book2->name = 'Ghost Story';
R::store($book2);
$fantasy = R::load('category', $cats[1]->id);
$cats = array();
$book = $book->fresh();
$book->fetchAs('category')->traverse('genre', function ($cat) use(&$cats) {
$cats[] = $cat->gname;
});
asrt(implode(',', $cats), 'SF,Fantasy');
$catList = array();
$fantasy->alias('genre')->with(' ORDER BY gname ASC ')->traverse('ownCategory', function ($cat) use(&$catList) {
$catList[] = $cat->gname;
});
asrt(implode(',', $catList), 'Horror,SF');
}