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

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

sledgehammer/orm
================

Sledgehammer ORM module: Object relational mapping

22.07.0(3y ago)485911CC-BY-SA-3.0PHP

Since Oct 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/sledgehammer/orm)[ Packagist](https://packagist.org/packages/sledgehammer/orm)[ RSS](/packages/sledgehammer-orm/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (1)Versions (24)Used By (1)

Sledgehammer ORM
================

[](#sledgehammer-orm)

The Object-relational mapping (ORM) module for the Sledgehammer Framework.

Features
--------

[](#features)

- Full AutoCompletion support
- POCO support. The Repository can load Plain Old Class Objects (POCO's)
- Detect relations from the database
- An optional ActiveRecord frontend
- Linq style filtering support
- Support for complex property mapping. A column "city" can be mapped to property "address-&gt;city"
- 1 database record maps to only 1 instance. via an [IdentityMap](http://martinfowler.com/eaaCatalog/identityMap.html)
- Relations are objects, To set the "customer\_id" you'll set the "customer" property to a customer object.
- Cascading save(). A save will update &amp; insert all connected records.
- Support for multiple backends: PDO (MySQL, SQLite), Webservices (Twitter, etc)
- Clean queries. (No "1 = 1" where statements, etc)

Usage
-----

[](#usage)

```
use Sledgehammer\Orm\Repository;
// inside your bootstrap.php
$repo = Repository::instance();
$repo->registerBackend(new DatabaseRepositoryBackend("default")); // Extract models from the "default" database connection.

// Somewhere in your application
$repo = Repository::instance();
$customer = $repo->getCustomer($_GET['id']);
$customer->name = $_POST['name'];
$repo->saveCustomer($customer);

// When the Customer class extends Sledgehammer\ActiveRecord the familiar API is also available
$customer = Customer::one($_GET['id']);
$customer->name = $_POST['name'];
$customer->save();

// Linq style filtering
$selection = $repo->allCustomers()->where(array('name' => 'James Bond'))->where(function ($c) { return $c->isSpecialAgent(); });
$list = Customer::all()->select('name', 'id'); // Results in: array($id1 => $name1, $id2 => $name2, ...)
```

Relations and Placeholders
--------------------------

[](#relations-and-placeholders)

The relations of objects are loaded on demand via placeholder classes. Just use the object as if all the relations are already loaded:

```
$customer->orders[0]->product->title;

```

Works and provides autocompletion all the way.

A downside to the placeholder technique is that:

```
if ($customer->orders[0]->id === $order->id) { ... } // Always works

if ($customer->orders[0] === $order) { ...} // WRONG. Doesn't work reliably

```

This is because $order might still be a BelongsToHolder object that will be replaced when used (calling a function, getting or setting a property) Sidenote: A BelongsToHolder often knows the id value and reading $order-&gt;id won't trigger a replacement/query.

### Update a relation

[](#update-a-relation)

You wont find any "customer\_id" properties in the objects, to change the "customer\_id" you'll need to use a customer object.

```
$order->customer = $repo->getCustomer(1);
$repo->saveOrder($order);

```

Don't do this

```
$order->customer->id = 1; // WRONG
$repo->saveOrder($order);  // Throws Exception

```

This is because you're changing the customer object which the repository tries to save before the order and id changes aren't allowed.

Dictionary
----------

[](#dictionary)

Backend: A data retrieval and storing mechanism. Model: A configuration to map backend data to instances. Instance: An object that is created by the Repository from backend data based on a Model.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 99.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 ~162 days

Recently: every ~572 days

Total

23

Last Release

1379d ago

Major Versions

12.12.0 → 13.02.02013-01-29

13.05.1 → 16.05.02016-05-02

16.x-dev → 18.04.02018-04-27

18.08.0 → 22.07.02022-08-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/207248?v=4)[Bob Fanger](/maintainers/bfanger)[@bfanger](https://github.com/bfanger)

---

Top Contributors

[![bfanger](https://avatars.githubusercontent.com/u/207248?v=4)](https://github.com/bfanger "bfanger (162 commits)")[![mronitz](https://avatars.githubusercontent.com/u/1639583?v=4)](https://github.com/mronitz "mronitz (1 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/sledgehammer-orm/health.svg)](https://phpackages.com/packages/sledgehammer-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)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

PHPackages © 2026

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