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

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

sympress/orm
============

Doctrine-inspired ORM primitives for WordPress projects that keep wpdb as the database runtime.

0.2.0(1mo ago)153GPL-2.0-or-laterPHPPHP ^8.5CI passing

Since Jun 14Pushed 2w agoCompare

[ Source](https://github.com/SymPress/orm)[ Packagist](https://packagist.org/packages/sympress/orm)[ RSS](/packages/sympress-orm/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

SymPress ORM
============

[](#sympress-orm)

[![Checks](https://camo.githubusercontent.com/986796a6779867efa5ac14b124078910c1015e7e992f867a12d0ca2f63dfa1bd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f53796d50726573732f6f726d2f71612e796d6c3f6272616e63683d6d61696e266c6162656c3d636865636b73)](https://github.com/SymPress/orm/actions/workflows/qa.yml) [![Release](https://camo.githubusercontent.com/1bc2f90ecd1c4999b56adf9e45b5605bf4d67ebbcc7c332ed5cf9ead45fb3dd4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f53796d50726573732f6f726d3f6c6162656c3d72656c65617365)](https://github.com/SymPress/orm/releases) [![PHP](https://camo.githubusercontent.com/3981e1451ab098260342fd194994bf3a080407df232574c49c01b77896a41354/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f73796d70726573732f6f726d2f7068702e7376673f6c6162656c3d706870)](https://packagist.org/packages/sympress/orm) [![Downloads](https://camo.githubusercontent.com/6bac34edc7f62207dbace54ca602e32aa54dee59876a0faed0d916ff97efc0fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73796d70726573732f6f726d2e7376673f6c6162656c3d646f776e6c6f616473)](https://packagist.org/packages/sympress/orm/stats) [![License: GPL-2.0-or-later](https://camo.githubusercontent.com/26f8b6541ea045cc1dbc2267208158b5a7ebbf5cf437c4b486d80fee9386f77e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c2d2d322e302d2d6f722d2d6c617465722d626c75652e737667)](composer.json)

> **Status:** WIP (Work in Progress)

Doctrine-inspired ORM primitives for WordPress projects that keep `wpdb` as the database runtime.

The package is intentionally not a full Doctrine ORM replacement. It brings the parts that are useful in a WordPress package architecture: attribute-based entity metadata, repositories, a Doctrine-like entity manager, deferred `flush()` writes, simple query building, schema SQL generation, and optional integration with `sympress/migration`.

WordPress remains the runtime. Existing plugins, core tables, `$wpdb`, and WordPress APIs continue to work normally.

Installation
------------

[](#installation)

```
composer require sympress/orm
```

When `sympress/kernel` is active, the package is discovered as a library bundle and registers its services and console commands automatically.

The root project should also require `sympress/migration` when ORM-managed schema migrations should be registered and executed through the migration system.

Features
--------

[](#features)

- Attribute mapping with `#[Entity]`, `#[Table]`, `#[Column]`, `#[Index]`, `#[UniqueConstraint]`, `#[MappedSuperclass]`, embeddables, and PHP enums
- Identifier mapping with `#[Id]`
- Generated identifiers with `#[GeneratedValue]`
- Cache mapping with `#[Cache]` on entities and associations
- To-one and to-many association mapping with simple or composite join columns and join tables
- Lazy to-many collections
- Cascade persist/remove and owning many-to-many join-table synchronization
- Lifecycle callbacks and event listeners for common ORM lifecycle events
- Entity metadata discovery from active SymPress kernel bundles
- Optional metadata cache
- Doctrine-like `EntityManager`
- Deferred persistence with `persist()` and `flush()`
- `UnitOfWork` with managed entities, original data snapshots, identity map, entity states, scheduled insertions, scheduled deletions, and change detection
- CRUD-oriented `Repository`
- `find()`, `findAll()`, `findBy()`, and `findOneBy()`
- Explicit `remove()`, `detach()`, `clear()`, `close()`, `refresh()`, and `contains()`
- Lazy entity references with `getReference()`
- Transaction helper with `transactional()`
- Automatic transaction wrapping during `flush()`
- Version columns, optimistic lock checks, and pessimistic lock helpers
- Deferred implicit and deferred explicit change tracking
- Hydration and extraction for scalar, date, datetime, boolean, JSON, and array column values
- Query builder with entity-field-to-column translation, joins, grouping, join conditions, grouping, ordering, limits, offsets, object parameters, and array parameters
- DQL-style `SELECT`, `UPDATE`, and `DELETE` queries with mapped fields, joins, named parameters, positional parameters, expanded array parameters, custom DQL functions, and output walkers
- Criteria objects, scalar/array result helpers, iterable results, and optional query result caching
- Optional second-level entity and association cache with simple cache regions
- Schema SQL generation for WordPress-friendly `CREATE TABLE` statements
- Live schema update SQL for missing and changed columns/indexes, opt-in destructive drops, and missing join tables, including single-table inheritance table deduplication
- `dbDelta()` compatibility through generated `CREATE TABLE` SQL
- Mapping validation for identifiers, associations, join metadata, and inheritance discriminator metadata
- Optional migration bridge for `sympress/migration`
- Console commands for mapping inspection, schema SQL, and migration class generation

Entity Mapping
--------------

[](#entity-mapping)

```
