-
Notifications
You must be signed in to change notification settings - Fork 0
Entity Definition
lpachecob edited this page Mar 23, 2026
·
4 revisions
In BOUNDLY, your domain entities are your database schema. No migrate files needed. Just attributes.
Required for every persistent class.
| Property | Default | Description |
|---|---|---|
table |
NULL |
The DB table name. |
resource |
NULL |
The API resource name (plural). |
primaryKey |
'id' |
The PK column name. |
connection |
'mysql' |
DB connection to use. |
#[Entity(table: 'users', resource: 'users')]
class User extends AggregateRoot { ... }Defines the DB column properties.
| Property | Default | Description |
|---|---|---|
type |
'string' |
The type (string, integer, boolean, decimal, etc.). |
length |
255 |
Max length for strings. |
nullable |
false |
If TRUE, the DB column will allow NULLs. |
default |
NULL |
The default value for the column. |
unique |
false |
If TRUE, adds a unique index in the DB. |
#[Column(type: 'string', length: 150, unique: true)]
private string $email;Marks the primary key of the entity. Generally used with private int $id.
Define database associations directly on your properties. BOUNDLY manages the foreign keys and pivot tables automatically during core:migrate.
| Attribute | SQL Implication on core:migrate
|
|---|---|
#[BelongsTo(relatedEntity: User::class)] |
Auto-adds a user_id BIGINT component column. |
#[HasMany(relatedEntity: Post::class)] |
No schema changes here (handled by inverse BelongsTo). |
#[HasOne(relatedEntity: Profile::class)] |
No schema changes here (handled by inverse BelongsTo). |
#[ManyToMany(relatedEntity: Role::class)] |
Auto-creates a pivot table (e.g., role_user) with proper keys if not present. |
💡 Tip: When you use
#[BelongsTo], you don't need to manually declare a#[Column]for the foreign key. BOUNDLY handles the DDL logic.
-
string(VARCHAR) -
text(TEXT) -
integer(INT) -
boolean(TINYINT) -
decimal(DECIMAL) -
date/datetime/timestamp -
json(JSON)
use Infrastructure\FrameworkCore\Attributes\{Entity, Id, Column};
use Infrastructure\FrameworkCore\Attributes\{BelongsTo, ManyToMany};
#[Entity(table: 'posts', resource: 'posts')]
class Post extends AggregateRoot
{
#[Id]
private int $id;
#[Column(type: 'string', length: 100)]
private string $title;
#[Column(type: 'text')]
private string $content;
#[Column(type: 'boolean', default: false)]
private bool $is_published;
#[BelongsTo(relatedEntity: User::class)]
private array $author;
#[ManyToMany(relatedEntity: Tag::class)]
private array $tags;
}Next Step: Action-Definition 🚀