\Dewdrop\DbRow

The Row class provides a simple way to manipulate the values associated with a single database row.

You can set values on the row using the set() method like this:

$row->set('column_name', $value);

Or, you can set multiple values at once like this:

$row->set(
    array(
        'column_name'   => $value,
        'second_column' => $anotherValue
    )
);

Setting and retrieving values can also be done via direct object or array-style use of the object:

// Access a column's value with object syntax
echo $row->column_name;

// Access a column's value with array syntax
echo $row['column_name'];

// Set a column's value with object syntax
$row->column_name = 'Value';

// Set a column's value with array syntax
$row['column_name'] = 'Value';

Once the columns have been assigned the desired values, you can call save(), which will either update or insert the row depending upon whether it already exists in the database. After saving, the row's data is automatically refreshed to ensure it still accurately represents the corresponding row in the database. For example, if it is a new row, the primary key's value will be populated after calling save().

Additionally, you can retrieve field objects representing columns in this row by calling its field() method:

$row->field('column_name');

The field object allows you to easily integrate with other Dewdrop APIs, leveraging the database metadata to add validators, retrieve lists of options, etc.

Summary

Methods
Properties
Constants
__construct()
init()
setTable()
getTable()
field()
__set()
offsetSet()
set()
__get()
offsetGet()
get()
__isset()
offsetExists()
has()
__unset()
offsetUnset()
save()
isNew()
delete()
getData()
toArray()
shortcode()
No public properties found
No constants found
No protected methods found
$data
$columns
N/A
refresh()
assembleUpdateWhereClause()
$table
$virtualFieldsInitialized
N/A

Properties

$data

$data : array

The data represented by this row.

Type

array

$columns

$columns : array

The columns available to this row as defined by the associated table's metadata.

Type

array

$table

$table : \Dewdrop\Db\Table

The table this row is associated with.

Type

\Dewdrop\Db\Table

$virtualFieldsInitialized

$virtualFieldsInitialized : array

A map of many-to-many and EAV fieldsthat tracks whether their initial value has been loaded yet. If not, the first time get() is called on this row for the field, the value will be loaded from the database.

Type

array

Methods

__construct()

__construct(\Dewdrop\Db\Table  $table, array  $data = array()) 

Instantiate the row, checking to ensure the data array contains only those columns present in the table's metadata.

Parameters

\Dewdrop\Db\Table $table
array $data

init()

init() : void

This method can be used by sub-classes to store initial values (for comparison during saving, for example).

setTable()

setTable(\Dewdrop\Db\Table  $table) : $this

Provide a new table instance for the row. Mostly useful if you're implementing a __wakeup() method.

Parameters

\Dewdrop\Db\Table $table

Returns

$this

getTable()

getTable() : \Dewdrop\Db\Table

Get the table associated with this row.

Returns

\Dewdrop\Db\Table

field()

field(string  $name) : \Dewdrop\Db\Field

Retrieve a field object representing the specified column name.

Parameters

string $name

Returns

\Dewdrop\Db\Field

__set()

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

Allow setting of data properties on this row via direct object property syntax:

$row->property_id = $value;

Parameters

string $key
mixed $value

offsetSet()

offsetSet(string  $key, mixed  $value) : void

Allow setting of data properties on this row via direct array syntax:

$row['property_id'] = $value;

This is part of the ArrayAccess interface built into PHP.

Parameters

string $key
mixed $value

set()

set(string|array  $column, mixed  $value = null) : $this

The the value of one or more columns on this row.

If $name is a string, that single column will be set. If $name is an array, the array will be iterated and each key-value pair will be set on the row.

Parameters

string|array $column
mixed $value

Throws

\Dewdrop\Exception

Returns

$this

__get()

__get(string  $key) : mixed

Allow retrieval of data values via direct object property access:

echo $row->property_id;

Parameters

string $key

Returns

mixed

offsetGet()

offsetGet(string  $key) : mixed

Allow retrieval of data values via direct array access:

echo $row['property_id'];

This method is part of the ArrayAccess interface built into PHP.

Parameters

string $key

Returns

mixed

get()

get(string  $name) : mixed

Get the value of the specified column.

Parameters

string $name

Throws

\Dewdrop\Exception

Returns

mixed

__isset()

__isset(string  $key) : boolean

Test to see if a given column exists on this row using object syntax:

isset($row->column_name);

Parameters

string $key

Returns

boolean

offsetExists()

offsetExists(string  $key) : boolean

Test to see if a given column exists on this row using array syntax:

isset($row['column_name']);

This method is part of the ArrayAccess interface built into PHP.

Parameters

string $key

Returns

boolean

has()

has(string  $name) : boolean

Test to see if the given column exists on this row.

Parameters

string $name

Returns

boolean

__unset()

__unset(string  $key) 

We do not allow unsetting columns on a row.

Parameters

string $key

Throws

\Dewdrop\Exception

offsetUnset()

offsetUnset(string  $key) 

Even though this method is required by the ArrayAccess interface, we do not allow unsetting columns on a row.

Parameters

string $key

Throws

\Dewdrop\Exception

save()

save() : $this

Save this row, inserting if it is a new row and updating otherwise.

Returns

$this

isNew()

isNew() : boolean

Determine whether this row is new or already present in the DB by checking if its primary key columns have a value assigned.

Returns

boolean

delete()

delete() : integer

Deletes existing rows.

Returns

integer —

The number of rows deleted.

getData()

getData() : array

Returns the row data.

Returns

array

toArray()

toArray() : array

Returns an array representation of the row data.

Returns

array

shortcode()

shortcode() : string

Returns

string

refresh()

refresh() : $this

Refresh the row, pulling in the latest data from the DB.

Returns

$this

assembleUpdateWhereClause()

assembleUpdateWhereClause() : string

Assemble the WHERE clause for the update method using the primary key column's from the associated table.

Returns

string