This documentation describes unreleased changes on the main branch.

AbstractRow

Abstract class.

use Saij\WpAppFramework\Table\AbstractRow;

The object of a row of a table of your own: a class with #[Table] extends it, and its promoted constructor parameters are the columns.

A row object is loaded with LogEntry::get($id) or LogEntry::find($id), found with LogEntry::query() and created with new LogEntry(…). save() inserts a new row and sets its primary key, or writes the changed columns of a loaded one; a row object with a primary key whose row does not exist is inserted with that key. delete() deletes it.

Every get(), find() and query returns new objects; when two of them change the same row, the last save() of a column wins. save() and delete() check no capabilities.

Methods

find()

AbstractRow::find(int $id): ?static

The row with the primary key, null if it does not exist.

ParameterTypeDefaultDescription
idintrequiredThe primary key of the row.

Returns ?AbstractRow

get()

AbstractRow::get(int $id): static

The row with the primary key.

ParameterTypeDefaultDescription
idintrequiredThe primary key of the row.

Returns AbstractRow

Throws InvalidArgumentException: If it does not exist.

query()

AbstractRow::query(): RowQuery

A query for rows of the table: all rows in the order of their primary key, see RowQuery.

Returns RowQuery<AbstractRow>

tableName()

AbstractRow::tableName(): string

The full name of the table on the current site, for SQL of your own: {$wpdb->prefix}{namespace}_{name}.

Returns non-empty-string

delete()

delete(): void

Deletes the row; its primary key is null afterwards, so save() would insert it again.

Throws LogicException: If the row has not been saved yet.

save()

save(): void

Inserts the row and sets its primary key, or writes the columns changed since it was loaded or saved; without changes, nothing is written. With a primary key whose row does not exist (set in new, or the row was deleted in the meantime and the object changed since), the row is inserted with that primary key and all columns.

Throws RuntimeException: If the database refuses the row, e.g. a string longer than its column.