PHPackages                             richbuilds/orm - 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. richbuilds/orm

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

richbuilds/orm
==============

A wireless ORM for PHP

17[1 issues](https://github.com/richardathome/Orm/issues)PHP

Since Jul 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/richardathome/Orm)[ Packagist](https://packagist.org/packages/richbuilds/orm)[ RSS](/packages/richbuilds-orm/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![RichBuilds Components](/docs/richbuilds_logo.png)](https://richbuilds.com)

🔗 ORM
=====

[](#-orm)

A wireless, typesafe ORM for PHP 8.1.

Currently only MySql data sources are supported, but Sqlite and Postgres are planned.

The ORM takes all it's instruction from the database. Make sure your primary and foreign keys are set up correctly.

Example usage:
--------------

[](#example-usage)

```
$orm = new Orm(new PDO('dsn','username','password'));
```

Model
=====

[](#model)

- represent a row in a table

Create an empty model
---------------------

[](#create-an-empty-model)

- fails if table doesn't exist

```
$post = $orm->Model('posts');
```

Set a column value
------------------

[](#set-a-column-value)

- fails if column doesn't exit
- fails if value is not a compatible datatype for the column

```
$post->set('title', 'My Post Title');
```

Set multiple column values
--------------------------

[](#set-multiple-column-values)

- no columns are changed if any fail

```
$post->set([
    'title'='My Post Title',
    'body'=>'My post body.',
    'created'=>new Datetime()
]);
```

Set a foreign key column to an existing record
----------------------------------------------

[](#set-a-foreign-key-column-to-an-existing-record)

- fails if the parent record doesn't exist

```
$post->set('author_id', 1);
```

Set a foreign key column to a new Model
---------------------------------------

[](#set-a-foreign-key-column-to-a-new-model)

- fails if Model is not of correct type

```
$user = $orm->Model('user');
$post->set('author_id', $user);
```

Set a foreign key column to n array of parent model values
----------------------------------------------------------

[](#set-a-foreign-key-column-to-n-array-of-parent-model-values)

```
$user = ['name'=>'foo','password'=>'password'];
$post->set('author_id', $user);
```

Set the children of a model
===========================

[](#set-the-children-of-a-model)

- accepts arrays of fields or models

```
$user->set('comments',[
    ['comment'=>'foo', 'visible'=>false],
    $orm->Model('comments')->set('comment', 'bar')
]);
```

Save the model, it's parents and it's children
==============================================

[](#save-the-model-its-parents-and-its-children)

- inside transaction, rolls back on error
- all keys are updated

```
$post->save();
echo $post->getPk();
```

Fetch a parent model
====================

[](#fetch-a-parent-model)

- fails if column name is not a foreign key or parent doesn't exist

```
$author = $post->fetchParent('author_id');
// SELECT * FROM users WHERE users.id = posts.author_id
echo $author->get('name');
```

Fetch children lazily
=====================

[](#fetch-children-lazily)

- fails if child table name is not a child of the parent

```
$posts = $user->fetchChildrent('posts');
// SELECT * FROM posts WHERE posts.author_id = user.id
```

Query
=====

[](#query)

Create a query
--------------

[](#create-a-query)

```
$posts = $orm->Query('posts',
    [
        'author_id'=>1
    ],
    [
        'per_page'=>10
    ]
)

// SELECT * FROM database.posts WHERE database.posts.author_id = :1 LIMIT 10 OFFSET 0;

foreach($posts as $post) {
  echo $post->get('title');
  $comments = $post->fetchChildren('comments');
}
```

###  Health Score

9

—

LowBetter than 0% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/14c260005a69b17ccb71e8a10be15f34aea6c26c12611bc7c91ff940bed4ce15?d=identicon)[richbuilds](/maintainers/richbuilds)

---

Top Contributors

[![richardathome](https://avatars.githubusercontent.com/u/40023?v=4)](https://github.com/richardathome "richardathome (36 commits)")

---

Tags

databasedbalorm

### Embed Badge

![Health badge](/badges/richbuilds-orm/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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