Fork me on GitHub

Nextras\Orm

Nextras\Orm is the next generation Orm designed for efficiency and simple usage. It is highly customizable, you can create your own mapper layer to use your favorite storage.

Code example

$author = new Author();
$author->name = 'Jon Snow';
$author->born = 'yesterday';
$author->mail = 'snow@wall.st';

$publisher = new Publisher();
$publisher->name = '7K publisher';

$book = new Book();
$book->title = 'My Life on The Wall';
$book->author = $author;
$book->publisher = $publisher;

$orm->books->persistAndFlush($book);

Calling persistAndFlush() on $book recursively persists author, publisher and book.

Performance

Nextras\Orm uses constant number of queries: it does not matter, how much data you will ouput or how many inner cycles you will use. Orm will fetch all needed data in advance. Let's see an exmaple:

$authors = $orm->authors->findAll();
foreach ($authors as $author) {
    echo $author->name;

    foreach ($author->books as $book) {
        echo $book->title;
        echo $book->translator->name;

        foreach ($book->tags as $tag) {
            echo $tag->name;
        }
    }
}

The code above will run 4 queries:

  1. to select all the authors,
  2. to select all books which were authored by previously selected authors,
  3. to select all translators who translated the previously selected books,
  4. to select all tags for previously selected books.

As you can see, Orm will not query in each cycle pass, rather it will query all the needed data at once.