Skip to main content

What is Id?

The Id class is a smart wrapper for entity identifiers. It automatically tracks whether an entity is new (needs INSERT) or existing (needs UPDATE).

Creating IDs

Auto-generated (New Entity)

From Existing Value (From Database)

Why This Matters

The isNew() method enables repositories to decide between INSERT and UPDATE:

Comparison & Equality

IDs can be compared with other IDs or strings:

Entity Equality

Entities use ID for equality comparison:

Working with Collections

IDs make it easy to find entities in collections:

Serialization

IDs serialize to their string value:

UUID Generation

When no value is provided, Id generates a UUID v4:

Practical Example

API Reference

Constructor

Static Methods

Instance Methods

Properties