Karlos
2/22/2018 - 1:17 PM

Nette Database Related

Nette Database Related

$books = $context->table('book');

foreach ($books as $book) {
    echo 'title:      ' . $book->title;
    echo 'written by: ' . $book->author->name; // $book->author je řádek z tabulky 'author'

    echo 'tags: ';
    foreach ($book->related('book_tag') as $bookTag) {
        echo $bookTag->tag->name . ', '; // $bookTag->tag je řádek z tabulky 'tag'
    }
}

$author->related('book.translator_id');
// je stejné jako
$author->related('book', 'translator_id');