ORM
abstract class ORM implements JsonSerializable
ORM.
Constants
PRIMARY_KEY_TYPE_INCREMENTING |
Incrementing primary key. |
PRIMARY_KEY_TYPE_UUID |
UUID primary key. |
PRIMARY_KEY_TYPE_CUSTOM |
Custom primary key. |
PRIMARY_KEY_TYPE_NONE |
No primary key. |
Properties
protected string | $connectionName | Connection name to use for the model. | |
static protected ConnectionManager | $connectionManager | Connection manager instance. | |
static protected array | $traitHooks | ORM query builder hooks. | |
static protected array | $traitCasts | Trait casts. | |
protected string | $tableName | Table name. | |
protected string | $foreignKeyName | Foreign key name. | |
protected string | $primaryKey | Primary key. | |
protected int | $primaryKeyType | Does this table have an auto increment primary index? | |
protected bool | $isPersisted | Has the record been loaded from/saved to a database? | |
protected array | $columns | Column values. | |
protected array | $original | Original column values. | |
protected array | $including | Relations to eager load. | |
protected array | $related | Related records. | |
protected array | $cast | Columns that should be casted to a specific type. | |
protected array | $assignable | Columns that can be set through mass assignment. | |
protected array | $protected | Columns and relations that are excluded from the array and json representations of the record. | |
protected string | $dateOutputFormat | Date format used when returning array and json representations of the record. |
Methods
Constructor.
Making sure that cloning returns a "fresh copy" of the record.
Returns the connection of the model.
Has the record been loaded from/saved to a database?
Synchronizes the original values with the modified values.
Gets the date format from the query builder compiler.
Registers hooks and casts.
Binds the hooks to the current instance of "$this".
Returns hooks for the chosen event.
Returns the short name of a class.
Returns the table name of the model.
Returns the primary key of the table.
Returns the primary key type.
Returns the primary key value.
Returns the foreign key of the table.
Returns the namespaced class name of the model.
Sets the relations to eager load.
Returns the relations to eager load.
Sets eagerly loaded related records.
Returns TRUE if the model has included the relationship and FALSE if not.
Eager loads relations on the model.
Returns the related records array.
Cast value to the appropriate type.
Sets a raw column value.
Sets a column value.
Gets a raw column value.
Returns a column value.
Returns TRUE if it's probable that $name is a relation and FALSE if not.
Gets a column value or relation.
Returns the columns array.
Sets column values.
Assigns the column values to the model.
Set column value using overloading.
Get column value or relation using overloading.
Checks if a column or relation is set using overloading.
Unset column value or relation using overloading.
Returns a record using the value of its primary key.
Creates a new record and returns the model.
Returns a HasOnePolymorphic relation.
Returns a HasManyPolymorphic relation.
Returns a ManyToMany relation.
Returns a BelongsToPolymorphic relation.
Has the record been modified?
Returns the modified column values of the record.
Generates a primary key.
Saves the record to the database.
Deletes a record from the database.
Excludes the chosen columns and relations from array and json representations of the record.
Exposes the chosen columns and relations in the array and json representations of the record.
Returns an array representation of the record.
Returns data which can be serialized by json_encode().
Returns a json representation of the record.
Returns a json representation of the record.
Forwards method calls to the query builder.
Forwards static method calls to the query builder.
Details
at line 203
__construct(array $columns = [], bool $raw = false, bool $whitelist = true, bool $isPersisted = false)
Constructor.
at line 220
__clone()
Making sure that cloning returns a "fresh copy" of the record.
at line 237
static
setConnectionManager(ConnectionManager $connectionManager)
Set the connection manager.
at line 247
Connection
getConnection()
Returns the connection of the model.
at line 262
bool
isPersisted()
Has the record been loaded from/saved to a database?
at line 270
synchronize()
Synchronizes the original values with the modified values.
at line 280
protected string
getDateFormat()
Gets the date format from the query builder compiler.
at line 295
protected
registerHooksAndCasts()
Registers hooks and casts.
at line 325
protected array
bindHooks(array $hooks)
Binds the hooks to the current instance of "$this".
at line 343
array
getHooks(string $event)
Returns hooks for the chosen event.
at line 354
protected string
getClassShortName(string|null $className = null)
Returns the short name of a class.
at line 373
string
getTable()
Returns the table name of the model.
at line 388
string
getPrimaryKey()
Returns the primary key of the table.
at line 398
int
getPrimaryKeyType()
Returns the primary key type.
at line 408
mixed
getPrimaryKeyValue()
Returns the primary key value.
at line 418
string
getForeignKey()
Returns the foreign key of the table.
at line 433
string
getClass()
Returns the namespaced class name of the model.
at line 443
setIncludes(array $includes)
Sets the relations to eager load.
at line 453
array
getIncludes()
Returns the relations to eager load.
at line 464
setRelated(string $relation, mixed $related)
Sets eagerly loaded related records.
at line 475
bool
includes(string $relation)
Returns TRUE if the model has included the relationship and FALSE if not.
at line 486
$this
include(array|string $includes)
Eager loads relations on the model.
at line 501
array
getRelated()
Returns the related records array.
at line 513
protected mixed
cast(string $name, mixed $value)
Cast value to the appropriate type.
at line 543
setRawColumnValue(string $name, mixed $value)
Sets a raw column value.
at line 554
setColumnValue(string $name, mixed $value)
Sets a column value.
at line 574
mixed
getRawColumnValue(string $name)
Gets a raw column value.
at line 585
mixed
getColumnValue(string $name)
Returns a column value.
at line 601
protected bool
isRelation(string $name)
Returns TRUE if it's probable that $name is a relation and FALSE if not.
at line 612
mixed
getValue(string $name)
Gets a column value or relation.
at line 643
array
getRawColumnValues()
Returns the columns array.
at line 654
protected
setColumValues(array $columns, bool $raw)
Sets column values.
at line 687
$this
assign(array $columns, bool $raw = false, bool $whitelist = true)
Assigns the column values to the model.
at line 716
__set(string $name, mixed $value)
Set column value using overloading.
at line 727
mixed
__get(string $name)
Get column value or relation using overloading.
at line 738
bool
__isset(string $name)
Checks if a column or relation is set using overloading.
at line 753
__unset(string $name)
Unset column value or relation using overloading.
at line 763
Query
builder()
Returns a query builder instance.
at line 775
static ORM|null
get(mixed $id, array $columns = [])
Returns a record using the value of its primary key.
at line 788
static ORM
create(array $columns = [], bool $raw = false, bool $whitelist = true)
Creates a new record and returns the model.
at line 804
protected HasOne
hasOne(string $model, string|null $foreignKey = null)
Returns a HasOne relation.
at line 818
protected HasOnePolymorphic
hasOnePolymorphic(string $model, string $polymorphicType)
Returns a HasOnePolymorphic relation.
at line 832
protected HasMany
hasMany(string $model, string|null $foreignKey = null)
Returns a HasMany relation.
at line 846
protected HasManyPolymorphic
hasManyPolymorphic(string $model, string $polymorphicType)
Returns a HasManyPolymorphic relation.
at line 862
protected ManyToMany
manyToMany(string $model, string|null $foreignKey = null, string|null $junctionTable = null, string|null $junctionKey = null)
Returns a ManyToMany relation.
at line 876
protected BelongsTo
belongsTo(string $model, string|null $foreignKey = null)
Returns a BelongsTo relation.
at line 890
protected BelongsToPolymorphic
belongsToPolymorphic(string $model, string $polymorphicType)
Returns a BelongsToPolymorphic relation.
at line 902
bool
isModified()
Has the record been modified?
at line 912
array
getModified()
Returns the modified column values of the record.
at line 932
protected mixed
generatePrimaryKey()
Generates a primary key.
at line 942
protected
insertRecord(Query $query)
Inserts a new record into the database.
at line 970
protected bool
updateRecord(Query $query)
Updates an existing record.
at line 982
bool
save()
Saves the record to the database.
at line 1017
protected bool
deleteRecord(Query $query)
Deletes a record from the database.
at line 1027
bool
delete()
Deletes a record from the database.
at line 1053
$this
protect(array|false|string $column)
Excludes the chosen columns and relations from array and json representations of the record.
You expose all fields by passing FALSE.
at line 1067
$this
expose(array|string|true $column)
Exposes the chosen columns and relations in the array and json representations of the record.
You can expose all fields by passing TRUE.
at line 1079
array
toArray()
Returns an array representation of the record.
at line 1126
array
jsonSerialize()
Returns data which can be serialized by json_encode().
at line 1137
string
toJson(int $options = 0)
Returns a json representation of the record.
at line 1147
string
__toString()
Returns a json representation of the record.
at line 1159
mixed
__call(string $name, array $arguments)
Forwards method calls to the query builder.
at line 1171
static mixed
__callStatic(string $name, array $arguments)
Forwards static method calls to the query builder.