\Omega\Database AbstractModel

Abstract model class.

The AbstractModel class providing the base for model class.

Summary

Methods
Properties
Constants
setConnection
getConnection
setTable
getTable
with
query
__callStatic
__get
__set
save
delete
hasOne
hasMany
belongsTo
find
No public properties found
No public constants found
No protected methods found
connection
table
attributes
dirty
casts
No protected constants found
No private methods found
No private properties found
No private constants found

Properties

$connection

$connection : \Omega\Database\Adapter\DatabaseAdapterInterface

Current database instance.

Type

DatabaseAdapterInterface — Holds the current database instance.

$table

$table : string

Table name in the database.

Type

string — Holds the table name in the database.

$attributes

$attributes : array

Model attributes.

Type

array<string, mixed> — Holds the model attributes.

$dirty

$dirty : string[]

Modified attributes,.

Type

array<string|int, string> — Holds the modified attributes.

$casts

$casts : array

Attribute casting types.

Type

array<string, callable(mixed): mixed> — Holds an array of attributes casting types.

Methods

setConnection()

setConnection(\Omega\Database\Adapter\DatabaseAdapterInterface  $connection) : static

Set the model's database connection.

Parameters

\Omega\Database\Adapter\DatabaseAdapterInterface $connection

Holds the database connection.

Returns

static —

getConnection()

getConnection() : \Omega\Database\Adapter\DatabaseAdapterInterface

Get the model's database connection.

Returns

\Omega\Database\Adapter\DatabaseAdapterInterface —

Return the current instance of DatabaseAdapterInterface.

setTable()

setTable(string  $table) : static

Set the table name in the database.

Parameters

string $table

Holds the table name to set.

Returns

static —

getTable()

getTable() : string

Get the table.

Throws

\Omega\Database\Exception\UndefinedTableNameException

if the table is not set or getTable is not defined.

Returns

string —

Return the table name.

with()

with(array  $attributes = []) : static

Model with attributes,.

Parameters

array $attributes

Holds an array of attributes.

Returns

static —

query()

query() : mixed

Execute the query.

Throws

\Exception

Returns

mixed —

__callStatic()

__callStatic(string  $method, array  $parameters = []) : $this|mixed

Magic method to forward undefined method calls to the underlying query builder instance.

This method allows dynamic method calls on the ModelCollector, delegating them to the underlying query builder instance. This is particularly useful for building queries fluently.

Parameters

string $method

Holds the method name.

array $parameters

Holds the method parameters.

Throws

\Exception

if the tabl is not set or getTable is not defined.

Returns

$this|mixed —

Return $this if the method is fluent, otherwise, returns the method result.

__get()

__get(string  $property) : mixed

Magic get.

Parameters

string $property

Holds the property name.

Returns

mixed —

__set()

__set(string  $property, mixed  $value) : void

Set the property.

Parameters

string $property

Holds the property name.

mixed $value

Holds the property value.

Returns

void —

save()

save() : static

Save the model's changes to the database.

Throws

\Omega\Database\Exception\UndefinedTableNameException

if the table is not set or getTable is not defined.

Returns

static —

delete()

delete() : static

Delete the model from the database.

Throws

\Omega\Database\Exception\UndefinedTableNameException

if the table is not set or getTable is not defined.

Returns

static —

hasOne()

hasOne(string  $class, string  $foreignKey, string  $primaryKey = 'id') : \Omega\Database\Relationship

Define a "hasOne" relationship between models.

Parameters

string $class

Holds the name of the related model class.

string $foreignKey

Holds the foreign key in the current model.

string $primaryKey

Holds the primary key in the related model.

Returns

\Omega\Database\Relationship —

Return the current instance of relation.

hasMany()

hasMany(string  $class, string  $foreignKey, string  $primaryKey = 'id') : \Omega\Database\Relationship

Define a "hasNay" relationship between models.

Parameters

string $class

Holds the name of the related model class.

string $foreignKey

Holds the foreign key in the current model.

string $primaryKey

Holds the primary key in the related model.

Returns

\Omega\Database\Relationship —

Return the current instance of relation.

belongsTo()

belongsTo(string  $class, string  $foreignKey, string  $primaryKey = 'id') : \Omega\Database\Relationship

Define a "belongsTo" relationship between models.

Parameters

string $class

Holds the name of the related model class.

string $foreignKey

Holds the foreign key in the current model.

string $primaryKey

Holds the primary key in the related model.

Returns

\Omega\Database\Relationship —

Return the current instance of relation.

find()

find(int  $id) : static

Find a model by ID.

Parameters

int $id

Holds the ID of the model to find.

Returns

static —