Registers a batch of aliases in one go. This works the same as
fetchAs and setAutoResolve but explicitly. For instance if you register
the alias 'cover' for 'page' a property containing a reference to a
page bean called 'cover' will correctly return the page bean and not
a (non-existant) cover bean.
R::aliases( array( 'cover' => 'page' ) );
$book = R::dispense( 'book' );
$page = R::dispense( 'page' );
$book->cover = $page;
R::store( $book );
$book = $book->fresh();
$cover = $book->cover;
echo $cover->getMeta( 'type' ); //page
The format of the aliases registration array is:
{alias} => {actual type}
In the example above we use:
cover => page
From that point on, every bean reference to a cover
will return a 'page' bean. Note that with autoResolve this
feature along with fetchAs() is no longer very important, although
relying on explicit aliases can be a bit faster. /** * Test whether aliases are not used if not necessary: * when using fetchAs() or R::aliases(). * * @return void */ public function testAutoResolvAvoid() { R::setAutoResolve(TRUE); R::nuke(); $book = R::dispense('book'); $page = R::dispense('page'); $book->cover = $page; R::store($book); $book = $book->fresh(); asrt($book->getMeta('sys.autoresolved.cover'), NULL); $book->cover; asrt($book->getMeta('sys.autoresolved.cover'), 'page'); R::nuke(); $book = R::dispense('book'); $page = R::dispense('page'); $book->cover = $page; R::store($book); $book = $book->fresh(); asrt($book->getMeta('sys.autoresolved.cover'), NULL); $book->fetchAs('page')->cover; asrt($book->getMeta('sys.autoresolved.cover'), NULL); R::nuke(); R::aliases(array('cover' => 'page')); $book = R::dispense('book'); $page = R::dispense('page'); $book->cover = $page; R::store($book); $book = $book->fresh(); asrt($book->getMeta('sys.autoresolved.cover'), NULL); $cover = $book->cover; asrt($cover instanceof OODBBean, TRUE); asrt($cover->getMeta('type'), 'page'); asrt($book->getMeta('sys.autoresolved.cover'), NULL); R::aliases(array()); R::nuke(); R::setAutoResolve(FALSE); $book = R::dispense('book'); $page = R::dispense('page'); $book->cover = $page; R::store($book); $book = $book->fresh(); asrt($book->getMeta('sys.autoresolved.cover'), NULL); $book->cover; asrt($book->getMeta('sys.autoresolved.cover'), NULL); R::setAutoResolve(TRUE); }