Skip to content

Commit 1185ec5

Browse files
noescomnoescom
authored andcommitted
Extended README
1 parent 4b8b978 commit 1185ec5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,46 @@ This pattern is especially important for identity (auto-increment) primary keys,
269269
have an ID until after they're persisted to the database. ObjectQuel's entity manager uses this nullability
270270
to determine whether an entity is new and requires an INSERT rather than an UPDATE operation.
271271

272+
#### Immutable Entities
273+
274+
Immutable entities represent read-only data that should never be modified through the ORM. This is particularly
275+
useful for database views, read-only tables, or reference data that should only be queried but never persisted.
276+
277+
```php
278+
/**
279+
* @Orm\Table(name="v_customer_summary")
280+
* @Orm\Immutable
281+
*/
282+
class CustomerSummary {
283+
/**
284+
* @Orm\Column(name="customer_id", type="integer", primary_key=true)
285+
*/
286+
private ?int $customerId = null;
287+
288+
/**
289+
* @Orm\Column(name="total_orders", type="integer")
290+
*/
291+
private int $totalOrders;
292+
293+
/**
294+
* @Orm\Column(name="total_revenue", type="decimal")
295+
*/
296+
private float $totalRevenue;
297+
}
298+
```
299+
300+
The `@Orm\Immutable` annotation prevents any modification operations on the entity:
301+
- **INSERT operations** will throw an `OrmException` during flush
302+
- **UPDATE operations** will throw an `OrmException` during flush
303+
- **DELETE operations** will throw an `OrmException` during flush
304+
305+
Immutable entities can still be queried normally using `find()`, `findBy()`, and `executeQuery()`. They are
306+
ideal for:
307+
- Database views that aggregate or join data from multiple tables
308+
- Read-only reference tables
309+
- Audit logs or historical data that should never be modified
310+
- Reports or dashboards that consume pre-calculated data
311+
272312
## The ObjectQuel Language
273313

274314
ObjectQuel draws inspiration from QUEL, a pioneering database query language developed in the 1970s for the Ingres DBMS

0 commit comments

Comments
 (0)