Class TransformedFieldStorageBehavior
Base class for behaviors which store attributes in a different form than when the model and its attributes are loaded.
Its purpose is to be used in cases whenever the stored value in the database will be different in some way from the value of the attribute when it is loaded in the model. For example, storing a JSON string in a database record, and having the corresponding model attribute be the decoded JSON object as an associative array. Thus, the transformation is transparent and requires no extra action in the code where the model is being used.
In all child classes, methods TransformedFieldStorageBehavior::unpackAttribute()
and TransformedFieldStorageBehavior::packAttribute()
must be inverses of each other. In other words, given a value
X, the value returned by unpackAttribute(packAttribute(X)) should be identical
to X. This ensures that the storage of the data does not modify the data, one
critical requirement of all database-driven software. Exceptions can be made
only if any loss or addition of data is intentional and stops after a certain
number of iterations of packing and unpacking.
- CComponent
- CBehavior implements IBehavior
- CModelBehavior
- CActiveRecordBehavior
- TransformedFieldStorageBehavior
Indirect known subclasses
JSONEmbeddedModelFieldsBehavior, JSONFieldsDefaultValuesBehavior, NormalizedJSONFieldsBehaviorPackage: application\components
Author: Demitri Morgan <demitri@x2engine.com>
Located at x2engine/protected/components/TransformedFieldStorageBehavior.php
abstract public
|
#
packAttribute( mixed $name )
In child classes, this method takes the "working"/"unpacked" value of the attribute, and returns the value that is to be stored in the database. |
abstract public
|
#
unpackAttribute( mixed $name )
In child classes, this method returns the "working" value, after retrieval from the database. |
public
|
|
public
|
|
public
|
#
beforeSave( CModelEvent $event )
Responds to CActiveRecord::onBeforeSave event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner. You may set CModelEvent::isValid to be false to quit the saving process. |
public
|
|
public
|
afterDelete(),
beforeCount(),
beforeDelete(),
beforeFind(),
events()
|
afterConstruct(),
afterValidate(),
beforeValidate()
|
attach(),
detach(),
getEnabled(),
getOwner(),
setEnabled()
|
__call(),
__get(),
__isset(),
__set(),
__unset(),
asa(),
attachBehavior(),
attachBehaviors(),
attachEventHandler(),
canGetProperty(),
canSetProperty(),
detachBehavior(),
detachBehaviors(),
detachEventHandler(),
disableBehavior(),
disableBehaviors(),
enableBehavior(),
enableBehaviors(),
evaluateExpression(),
getEventHandlers(),
hasEvent(),
hasEventHandler(),
hasProperty(),
raiseEvent()
|
public
array
|
$transformAttributes | array() |
#
Array of attributes to transform. |
protected
type
|
$hasOptions | false |
#
If true, specifies that the array |
$owner
|
$enabled
|