Fork me on GitHub


composer require nextras/orm

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 layout.

Code example

$author = new Author();
$author->name = 'Jon Snow';
$author->born = 'yesterday';
$author->mail = '';

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

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


Calling persistAndFlush() on $book recursively persists the author, publisher and book entity and enclose the operation in a (database) transaction.


Nextras Orm provides mechanism to use constant number of queries: it does not matter, how much data you will fetch and ouput or how many inner cycles you will use. Orm will fetch all needed data efficiently in advance. Let's see an example:

$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 provided code will run only 4 queries:

  1. select all authors,
  2. select all books which were authored by previously selected authors,
  3. select all translators who translated the previously selected books,
  4. 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 data at once during the first pass.