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.

10PHP

Since Jun 13Pushed todayCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#sympress-orm)

> **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)

```
