PHPackages                             uestla/yetorm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. uestla/yetorm

ActiveLibrary[Database &amp; ORM](/categories/database)

uestla/yetorm
=============

Lightweight ORM for Nette\\Database

10.1.2(8y ago)4936.4k↓100%14MITPHPPHP &gt;=5.6.0

Since Apr 7Pushed 6y ago5 watchersCompare

[ Source](https://github.com/uestla/YetORM)[ Packagist](https://packagist.org/packages/uestla/yetorm)[ Docs](https://github.com/uestla/YetORM)[ RSS](/packages/uestla-yetorm/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (45)Used By (0)

YetORM
======

[](#yetorm)

[![Build Status](https://camo.githubusercontent.com/6e0d73002eb999fb05e8d6888d08673d1ca52475bfb41e84eff8015206fd688b/68747470733a2f2f7472617669732d63692e6f72672f756573746c612f5965744f524d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/uestla/YetORM)[![Code coverage](https://camo.githubusercontent.com/bd2cc27e911c66947895ae2ea0330bee31ee221dedb8cf29b80dcbcb32dd9da2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f756573746c612f5965744f524d2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/uestla/YetORM)[![Total downloads](https://camo.githubusercontent.com/ea8b960e223a2fb66e0fd9880fb711c138ae6ce78ebacb8cdd403be1f2cbbbdd/68747470733a2f2f706f7365722e707567782e6f72672f756573746c612f7965746f726d2f646f776e6c6f616473)](https://packagist.org/packages/uestla/YetORM)[![Latest stable](https://camo.githubusercontent.com/d920c1c456a2b7f1b5ce85414606b490b1a9d7d2a4097b16504cd4acf61b273a/68747470733a2f2f706f7365722e707567782e6f72672f756573746c612f7965746f726d2f762f737461626c65)](https://packagist.org/packages/uestla/YetORM)

Lightweight ORM built on top of Nette\\Database

[![Buy me a Coffee](https://camo.githubusercontent.com/648ad6f048733f167bf65e11a4fd759eef14da88db61ad078bbd5ddea5d57133/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f4c472e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=T4AW48GVJW8KY)

Quickstart
----------

[](#quickstart)

Consider following database schema:

[![Database schema](https://camo.githubusercontent.com/ac62b33d3d802c5d839499ff117b662e6633978b6fbc760f62fa40f3070ed161/687474703a2f2f692e696d6775722e636f6d2f45745231624d342e706e67)](https://camo.githubusercontent.com/ac62b33d3d802c5d839499ff117b662e6633978b6fbc760f62fa40f3070ed161/687474703a2f2f692e696d6775722e636f6d2f45745231624d342e706e67)

### Entities

[](#entities)

Firstly we'll create entity classes according to the schema above. There are two ways of defining entity properties - via `@property[-read]` annotation, or simply via getter and setter.

#### Tag

[](#tag)

```
/**
 * @property-read int $id
 * @property string $name
 */
class Tag extends YetORM\Entity
{}
```

#### Author

[](#author)

```
/**
 * @property-read int $id
 * @property string $name
 * @property string $web
 * @property \DateTime $born
 */
class Author extends YetORM\Entity
{}
```

#### Book

[](#book)

There are some relations at the `Book` entity - two N:1 `Author` and M:N `Tag` relations. Every `YetORM\Entity` has an instance of `YetORM\Record` in it, which is a simple wrapper around `Nette\Database\Table\ActiveRow`. That means that we can access related records or column values through it.

```
/**
 * @property-read int $id
 * @property string $title
 * @property string $web
 * @property string $slogan
 */
class Book extends YetORM\Entity
{
	function getAuthor()
	{
		return new Author($this->record->ref('author', 'author_id'));
	}

	function getMaintainer()
	{
		return new Author($this->record->ref('author', 'maintainer_id'));
	}

	function getTags()
	{
		$selection = $this->record->related('book_tag');
		return new YetORM\EntityCollection($selection, 'Tag', 'tag');
	}
}
```

With `$record->ref($table, $column)` we're accessing related table row in table `$table` through column `$column` - pretty simple.

The M:N relation is realized with `YetORM\EntityCollection` instance - which is a lazy collection of entities. In this case it iterates throw all related rows from `book_tag` table (first argument), creates instances of `Tag` (second argument) and on every related `book_tag` table row it accesses related `tag` table row (third argument), which then passes to the constructor of `Tag` entity :-)

This sounds crazy, but it's actually simple to get used to.

With this knowledge we can now simply add some helpful methods to `Author` entity:

```
// class Author
function getBooksWritten()
{
	$selection = $this->record->related('book', 'author_id');
	return new YetORM\EntityCollection($selection, 'Book');
}

function getBooksMaintained()
{
	$selection = $this->record->related('book', 'maintainer_id');
	return new YetORM\EntityCollection($selection, 'Book');
}
```

### Repositories

[](#repositories)

Every repository has to have table and entity class name defined - either via `@table` and `@entity` annotaion, or via protected `$table` and `$entity` class property.

```
/**
 * @table  book
 * @entity Book
 */
class BookRepository extends YetORM\Repository
{}
```

#### Fetching collections

[](#fetching-collections)

`YetORM\Repository` comes with basic `findAll()` and `findBy($criteria)` methods, both returning already mentioned `EntityCollection`.

We can simply iterate through all books

```
$books = new BookRepository($connection); // $connection instanceof Nette\Database\Context

foreach ($books->findAll() as $book) { // $book instanceof Book
	echo $book->title;
	echo $book->getAuthor()->name;
	foreach ($book->getTags() as $tag) { // $tag instanceof Tag
		echo $tag->name;
	}
}
```

#### Fetching single entity

[](#fetching-single-entity)

```
$book = $books->getByID(123); // instanceof Book or NULL if not found
```

#### Magic `findBy()` and `getBy()` methods

[](#magic-findbyproperty-and-getbyproperty-methods)

Instead of manually writing `findByTitle($title)` method as this

```
function findByTitle($title)
{
	return $this->findBy(array(
		'title' => $title,
	));
}
```

we can just call

```
$books->findByTitle($title); // without having the method implemented
```

That will return a collection of books with that exact title.

To get a single entity use the magic `getBy($value)` method:

```
$book = $books->getByIsbn(''); // instanceof Book or NULL if not found
```

Just to have the IDE code completion along with this magic methods, we can use the `@method` annotation:

```
/**
 * @table  book
 * @entity Book
 * @method YetORM\EntityCollection|Book[] findByTitle(string $title)
 * @method Book|NULL getByIsbn(string $isbn)
 */
class BookRepository extends YetORM\Repository
{}

/**
 * @property-read int $id
 * @property string $title
 * @property string $isbn
 */
 class Book extends Entity
 {}
```

> IMPORTANT: When using magic `findBy()` and `getBy()` methods, make sure you have the property defined via `@property` annotation!

> NOTE: magic `findBy()` and `getBy()` do not work on relational properties of type Entity.

#### Persisting

[](#persisting)

To persist changes we simply call `$repository->persist($entity)`.

```
$book->web = 'http://example.com';
$books->persist($book);
```

And that's it!

Additional notes
----------------

[](#additional-notes)

- **No identity map**
- **Query efficiency** - the collections (resp. `YetORM\Record`) use the power of `Nette\Database` efficiency
- **Collection operations** - collections can be sorted via `$coll->orderBy($column, $dir)` and limitted via `$coll->limit($limit, $offset)`

More
----

[](#more)

For more examples please see the [tests](https://github.com/uestla/YetORM/tree/master/tests).

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~41 days

Recently: every ~145 days

Total

44

Last Release

2952d ago

Major Versions

5.0.0 → 6.0.02014-05-28

6.0.3 → 7.0.02014-08-16

7.0.1 → 8.0.02014-09-10

8.0.7 → 9.0.02016-03-04

9.0.3 → 10.0.02016-07-13

PHP version history (3 changes)0.9.1PHP &gt;=5.3.0

9.0.0PHP &gt;=5.4.0

10.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d3a756def83a4d23274f1b7c7854f6eda71834901be89fc668f85f170f97653?d=identicon)[uestla](/maintainers/uestla)

---

Top Contributors

[![uestla](https://avatars.githubusercontent.com/u/373888?v=4)](https://github.com/uestla "uestla (291 commits)")[![mkoubik](https://avatars.githubusercontent.com/u/136466?v=4)](https://github.com/mkoubik "mkoubik (3 commits)")[![ondrakub](https://avatars.githubusercontent.com/u/137948?v=4)](https://github.com/ondrakub "ondrakub (3 commits)")[![f3l1x](https://avatars.githubusercontent.com/u/538058?v=4)](https://github.com/f3l1x "f3l1x (2 commits)")[![kravcik](https://avatars.githubusercontent.com/u/10499130?v=4)](https://github.com/kravcik "kravcik (2 commits)")[![Tharos](https://avatars.githubusercontent.com/u/866325?v=4)](https://github.com/Tharos "Tharos (1 commits)")

---

Tags

nettedatabaseorm

### Embed Badge

![Health badge](/badges/uestla-yetorm/health.svg)

```
[![Health](https://phpackages.com/badges/uestla-yetorm/health.svg)](https://phpackages.com/packages/uestla-yetorm)
```

###  Alternatives

[nettrine/orm

Doctrine ORM for Nette Framework

581.9M33](/packages/nettrine-orm)[kdyby/doctrine

Doctrine integration into Nette Framework

1091.0M84](/packages/kdyby-doctrine)[nettrine/extensions-atlantic18

Doctrine2 behavioral extensions for Nette Framework

13899.1k1](/packages/nettrine-extensions-atlantic18)[modul-is/orm

Lightweight hybrid ORM/Explorer

1117.8k](/packages/modul-is-orm)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
