Doctrine 1.2.4
Doctrine_Record Class Reference

Inherits Doctrine_Record_Abstract, Countable, IteratorAggregate, and Serializable.

Inherited by Doctrine_File, and Doctrine_File_Index.

Public Member Functions

 __construct ($table=null, $isNewEntry=false)
 
 __call ($method, $args)
 
 __get ($name)
 
 __isset ($name)
 
 __set ($name, $value)
 
 __toString ()
 
 __unset ($name)
 
 actAs ($tpl, array $options=array())
 
 add ($value)
 
 addListener ($listener, $name=null)
 
 assignDefaultValues ($overwrite=false)
 
 assignIdentifier ($id=false)
 
 assignInheritanceValues ()
 
 attribute ($attr, $value)
 
 bind ($name, $resource)
 
 bindQueryParts (array $queryParts)
 
 call ($callback, $column)
 
 check ($constraint, $name=null)
 
 cleanData (&$data)
 
 clearAccessor ($fieldName)
 
 clearInvokedSaveHooks ()
 
 clearMutator ($fieldName)
 
 clearRelated ($name=null)
 
 columnCount ()
 
 construct ()
 
 contains ($fieldName)
 
 copy ($deep=false)
 
 coreSetRelated ($name, $value)
 
 count ()
 
 delete (Doctrine_Connection $conn=null)
 
 deleteNode ()
 
 errorStack ($stack=null)
 
 exists ()
 
 exportTo ($type, $deep=true)
 
 free ($deep=false)
 
 fromArray (array $array, $deep=true)
 
 get ($offset)
 
 get ($fieldName, $load=true)
 
 getAccessor ($fieldName)
 
 getAccessors ()
 
 getData ()
 
 getErrorStack ()
 
 getErrorStackAsString ()
 
 getIncremented ()
 
 getIterator ()
 
 getLast ()
 
 getLastModified ($old=false)
 
 getListener ()
 
 getLocator ()
 
 getModified ($old=false, $last=false)
 
 getMutator ($fieldName)
 
 getMutators ()
 
 getNode ()
 
 getOid ()
 
 getPendingDeletes ()
 
 getPendingUnlinks ()
 
 getPrepared (array $array=array())
 
 getReferences ()
 
 getTable ()
 
 hasAccessor ($fieldName, $accessor=null)
 
 hasAccessorMutator ($fieldName, $accessor, $mutator)
 
 hasColumn ($name, $type=null, $length=null, $options=array())
 
 hasColumns (array $definitions)
 
 hasMany ()
 
 hasMappedValue ($name)
 
 hasMutator ($fieldName, $mutator=null)
 
 hasOne ()
 
 hasReference ($name)
 
 hasRelation ($fieldName)
 
 hydrate (array $data, $overwriteLocalChanges=true)
 
 identifier ()
 
 importFrom ($type, $data, $deep=true)
 
 index ($name, array $definition=array())
 
 invokeSaveHooks ($when, $type, $event=null)
 
 isInProxyState ()
 
 isModified ($deep=false)
 
 isValid ($deep=false, $hooks=true)
 
 link ($alias, $ids, $now=false)
 
 linkInDb ($alias, $ids)
 
 load (array $data=array())
 
 loadReference ($name)
 
 locate ($name)
 
 mapValue ($name, $value=null)
 
 merge ($data, $deep=true)
 
 obtainReference ($name)
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 option ($name, $value=null)
 
 postDelete ($event)
 
 postHydrate ($event)
 
 postInsert ($event)
 
 postSave ($event)
 
 postSerialize ($event)
 
 postUnserialize ($event)
 
 postUpdate ($event)
 
 postValidate ($event)
 
 preDelete ($event)
 
 preDqlDelete ($event)
 
 preDqlSelect ($event)
 
 preDqlUpdate ($event)
 
 preHydrate ($event)
 
 preInsert ($event)
 
 preSave ($event)
 
 preSerialize ($event)
 
 preUnserialize ($event)
 
 preUpdate ($event)
 
 preValidate ($event)
 
 rawGet ($fieldName)
 
 reference ($name)
 
 refresh ($deep=false)
 
 refreshRelated ($name=null)
 
 relatedExists ($name)
 
 remove ($offset)
 
 replace (Doctrine_Connection $conn=null)
 
 resetPendingUnlinks ()
 
 save (Doctrine_Connection $conn=null)
 
 serialize ()
 
 serializeReferences ($bool=null)
 
 set ($offset, $value)
 
 set ($fieldName, $value, $load=true)
 
 setArray (array $array)
 
 setColumnOption ($columnName, $option, $value)
 
 setColumnOptions ($name, array $options)
 
 setListener ($listener)
 
 setLocator (Doctrine_Locator $locator)
 
 setRelated ($alias, Doctrine_Access $coll)
 
 setUp ()
 
 state ($state=null)
 
 synchronizeWithArray (array $array, $deep=true)
 
 toArray ($deep=true, $prefixKey=false)
 
 toString ()
 
 trySave (Doctrine_Connection $conn=null)
 
 unique ($fields, $options=array(), $createUniqueIndex=true)
 
 unlink ($alias, $ids=array(), $now=false)
 
 unlinkInDb ($alias, $ids=array())
 
 unserialize ($serialized)
 

Static Public Member Functions

static _index ()
 
static getNullObject ()
 
static initNullObject (Doctrine_Null $null)
 

Data Fields

const STATE_CLEAN = 3
 
const STATE_DIRTY = 1
 
const STATE_LOCKED = 6
 
const STATE_PROXY = 4
 
const STATE_TCLEAN = 5
 
const STATE_TDIRTY = 2
 
const STATE_TLOCKED = 7
 

Protected Member Functions

 _isValueModified ($type, $old, $new)
 
 _resetModified ()
 
 validate ()
 
 validateOnInsert ()
 
 validateOnUpdate ()
 

Protected Attributes

 $_pendingUnlinks = array()
 
 $_table
 

Detailed Description

Definition at line 34 of file Record.php.

Constructor & Destructor Documentation

Doctrine_Record::__construct (   $table = null,
  $isNewEntry = false 
)

constructor

Parameters
Doctrine_Table | null$tablea Doctrine_Table object or null, if null the table object is retrieved from current connection
boolean$isNewEntrywhether or not this record is transient
Exceptions
Doctrine_Connection_Exceptionif object is created using the new operator and there are no open connections
Doctrine_Record_Exceptionif the cleanData operation fails somehow

Definition at line 211 of file Record.php.

{
if (isset($table) && $table instanceof Doctrine_Table) {
$this->_table = $table;
$exists = ( ! $isNewEntry);
} else {
// get the table of this class
$class = get_class($this);
$this->_table = Doctrine_Core::getTable($class);
$exists = false;
}
// Check if the current connection has the records table in its registry
// If not this record is only used for creating table definition and setting up
// relations.
if ( ! $this->_table->getConnection()->hasTable($this->_table->getComponentName())) {
return;
}
$this->_oid = self::$_index;
self::$_index++;
// get the data array
$this->_data = $this->_table->getData();
// get the column count
$count = count($this->_data);
$this->_values = $this->cleanData($this->_data);
$this->prepareIdentifiers($exists);
if ( ! $exists) {
if ($count > count($this->_values)) {
} else {
}
// set the default values for this record
} else {
if ($this->isInProxyState()) {
}
}
$repository = $this->_table->getRepository();
// Fix for #1682 and #1841.
// Doctrine_Table does not have the repository yet during dummy record creation.
if ($repository) {
$repository->add($this);
$this->construct();
}
}

Member Function Documentation

Doctrine_Record::__call (   $method,
  $args 
)

magic method used for method overloading

the function of this method is to try to find a given method from the templates (behaviors) the record is using, and if found, execute it. Note that already existing methods would not be overloaded.

So, in sense, this method replicates the usage of mixins (as seen in some programming languages)

Parameters
string$methodname of the method
array$argsmethod arguments
Returns
mixed the return value of the given method

Definition at line 2642 of file Record.php.

{
if (($template = $this->_table->getMethodOwner($method)) !== false) {
$template->setInvoker($this);
return call_user_func_array(array($template, $method), $args);
}
foreach ($this->_table->getTemplates() as $template) {
if (is_callable(array($template, $method))) {
$template->setInvoker($this);
$this->_table->setMethodOwner($method, $template);
return call_user_func_array(array($template, $method), $args);
}
}
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown method %s::%s', get_class($this), $method));
}
Doctrine_Access::__get (   $name)
inherited

Get key from data

See Also
get, offsetGet
Parameters
mixed$name
Returns
mixed

Definition at line 70 of file Access.php.

{
return $this->get($name);
}
Doctrine_Access::__isset (   $name)
inherited

Check if key exists in data

Parameters
string$name
Returns
boolean whether or not this object contains $name

Definition at line 81 of file Access.php.

{
return $this->contains($name);
}
Doctrine_Access::__set (   $name,
  $value 
)
inherited

Set key and value to data

See Also
set, offsetSet
Parameters
$name
$value
Returns
void

Definition at line 58 of file Access.php.

{
$this->set($name, $value);
}
Doctrine_Record::__toString ( )

magic method

Returns
string representation of this object

Definition at line 2714 of file Record.php.

{
return (string) $this->_oid;
}
Doctrine_Record::__unset (   $name)

deletes a column or a related component.

Parameters
string$name
Returns
void

Definition at line 1657 of file Record.php.

{
if (array_key_exists($name, $this->_data)) {
$this->_data[$name] = array();
} else if (isset($this->_references[$name])) {
if ($this->_references[$name] instanceof Doctrine_Record) {
$this->_pendingDeletes[] = $this->$name;
$this->_references[$name] = self::$_null;
} elseif ($this->_references[$name] instanceof Doctrine_Collection) {
$this->_pendingDeletes[] = $this->$name;
$this->_references[$name]->setData(array());
}
}
}
static Doctrine_Record::_index ( )
static

the current instance counter used to generate unique ids for php objects. Contains the next identifier.

Returns
integer

Definition at line 292 of file Record.php.

{
return self::$_index;
}
Doctrine_Record::_isValueModified (   $type,
  $old,
  $new 
)
protected

Check if a value has changed according to Doctrine Doctrine is loose with type checking in the same ways PHP is for consistancy of behavior

This function basically says if what is being set is of Doctrine type boolean and something like current_value == 1 && new_value = true would not be considered modified

Simply doing $old !== $new will return false for boolean columns would mark the field as modified and change it in the database when it is not necessary

Parameters
string$typeDoctrine type of the column
string$oldOld value
string$newNew value
Returns
boolean $modified Whether or not Doctrine considers the value modified

Definition at line 1534 of file Record.php.

{
if ($new instanceof Doctrine_Expression) {
return true;
}
if ($type == 'boolean' && (is_bool($old) || is_numeric($old)) && (is_bool($new) || is_numeric($new)) && $old == $new) {
return false;
} else if (in_array($type, array('decimal', 'float')) && is_numeric($old) && is_numeric($new)) {
return $old * 100 != $new * 100;
} else if (in_array($type, array('integer', 'int')) && is_numeric($old) && is_numeric($new)) {
return $old != $new;
} else if ($type == 'timestamp' || $type == 'date') {
$oldStrToTime = strtotime($old);
$newStrToTime = strtotime($new);
if ($oldStrToTime && $newStrToTime) {
return $oldStrToTime !== $newStrToTime;
} else {
return $old !== $new;
}
} else {
return $old !== $new;
}
}
Doctrine_Record::_resetModified ( )
protected

Reset the modified array and store the old array in lastModified so it can be accessed by users after saving a record, since the modified array is reset after the object is saved.

Returns
void

Definition at line 2621 of file Record.php.

{
if ( ! empty($this->_modified)) {
$this->_lastModified = $this->_modified;
$this->_modified = array();
}
}
Doctrine_Record_Abstract::actAs (   $tpl,
array  $options = array() 
)
inherited

Loads the given plugin.

This method loads a behavior in the record. It will add the behavior also to the record table if it. It is tipically called in

See Also
setUp().
Parameters
mixed$tplif an object, must be a subclass of Doctrine_Template. If a string, Doctrine will try to instantiate an object of the classes Doctrine_Template_$tpl and subsequently $tpl, using also autoloading capabilities if defined.
array$optionsargument to pass to the template constructor if $tpl is a class name
Exceptions
Doctrine_Record_Exceptionif $tpl is neither an instance of Doctrine_Template subclass or a valid class name, that could be instantiated.
Returns
Doctrine_Record this object; provides a fluent interface.

Definition at line 349 of file Abstract.php.

{
if ( ! is_object($tpl)) {
$className = 'Doctrine_Template_' . $tpl;
if (class_exists($className, true)) {
$tpl = new $className($options);
} else if (class_exists($tpl, true)) {
$tpl = new $tpl($options);
} else {
throw new Doctrine_Record_Exception('Could not load behavior named: "' . $tpl . '"');
}
}
if ( ! ($tpl instanceof Doctrine_Template)) {
throw new Doctrine_Record_Exception('Loaded behavior class is not an instance of Doctrine_Template.');
}
$className = get_class($tpl);
$this->_table->addTemplate($className, $tpl);
$tpl->setInvoker($this);
$tpl->setTable($this->_table);
$tpl->setUp();
$tpl->setTableDefinition();
return $this;
}
Doctrine_Access::add (   $value)
inherited

Add the value

Parameters
mixed$valueThe value to add
Returns
void

Definition at line 199 of file Access.php.

{
throw new Doctrine_Exception('Add is not supported for ' . get_class($this));
}
Doctrine_Record_Abstract::addListener (   $listener,
  $name = null 
)
inherited

addListener

Parameters
Doctrine_EventListener_Interface | Doctrine_Overloadable$listener
Returns
Doctrine_Record

Definition at line 67 of file Abstract.php.

{
$this->_table->addRecordListener($listener, $name);
return $this;
}
Doctrine_Record::assignDefaultValues (   $overwrite = false)

setDefaultValues sets the default values for records internal data

Parameters
boolean$overwritewhether or not to overwrite the already set values
Returns
boolean

Definition at line 683 of file Record.php.

{
if ( ! $this->_table->hasDefaultValues()) {
return false;
}
foreach ($this->_data as $column => $value) {
$default = $this->_table->getDefaultValueOf($column);
if ($default === null) {
continue;
}
if ($value === self::$_null || $overwrite) {
$this->_data[$column] = $default;
$this->_modified[] = $column;
}
}
}
Doctrine_Record::assignIdentifier (   $id = false)

assigns an identifier to the instance, for database storage

Parameters
mixed$ida key value or an array of keys
Returns
void

Definition at line 2231 of file Record.php.

{
if ($id === false) {
$this->_id = array();
$this->_data = $this->cleanData($this->_data);
$this->_resetModified();
} elseif ($id === true) {
$this->prepareIdentifiers(true);
$this->_resetModified();
} else {
if (is_array($id)) {
foreach ($id as $fieldName => $value) {
$this->_id[$fieldName] = $value;
$this->_data[$fieldName] = $value;
}
} else {
$name = $this->_table->getIdentifier();
$this->_id[$name] = $id;
$this->_data[$name] = $id;
}
$this->_resetModified();
}
}
Doctrine_Record::assignInheritanceValues ( )

Assign the inheritance column values

Returns
void

Definition at line 663 of file Record.php.

{
$map = $this->_table->inheritanceMap;
foreach ($map as $k => $v) {
$k = $this->_table->getFieldName($k);
$old = $this->get($k, false);
if (((string) $old !== (string) $v || $old === null) && !in_array($k, $this->_modified)) {
$this->set($k, $v);
}
}
}
Doctrine_Record_Abstract::attribute (   $attr,
  $value 
)
inherited

attribute sets or retrieves an option

See Also
Doctrine_Core::ATTR_* constants availible attributes
Parameters
mixed$attr
mixed$value
Returns
mixed

Definition at line 182 of file Abstract.php.

{
if ($value == null) {
if (is_array($attr)) {
foreach ($attr as $k => $v) {
$this->_table->setAttribute($k, $v);
}
} else {
return $this->_table->getAttribute($attr);
}
} else {
$this->_table->setAttribute($attr, $value);
}
}
Doctrine_Locator_Injectable::bind (   $name,
  $resource 
)
inherited

bind binds a resource to a name

Parameters
string$namethe name of the resource to bind
mixed$valuethe value of the resource
Returns
Doctrine_Locator this object

Definition at line 120 of file Injectable.php.

{
$this->_resources[$name] = $resource;
return $this;
}
Doctrine_Record_Abstract::bindQueryParts ( array  $queryParts)
inherited

bindQueryParts binds query parts to given component

Parameters
array$queryPartsan array of pre-bound query parts
Returns
Doctrine_Record this object

Definition at line 322 of file Abstract.php.

{
$this->_table->bindQueryParts($queryParts);
return $this;
}
Doctrine_Record::call (   $callback,
  $column 
)

call

Parameters
string | array$callbackvalid callback
string$columncolumn name
mixedarg1 ... argN optional callback arguments
Returns
Doctrine_Record provides a fluent interface

Definition at line 2376 of file Record.php.

{
$args = func_get_args();
array_shift($args);
if (isset($args[0])) {
$fieldName = $args[0];
$args[0] = $this->get($fieldName);
$newvalue = call_user_func_array($callback, $args);
$this->_data[$fieldName] = $newvalue;
}
return $this;
}
Doctrine_Record_Abstract::check (   $constraint,
  $name = null 
)
inherited

Adds a check constraint.

This method will add a CHECK constraint to the record table.

Parameters
mixed$constrainteither a SQL constraint portion or an array of CHECK constraints. If array, all values will be added as constraint
string$nameoptional constraint name. Not used if $constraint is an array.
Returns
Doctrine_Record this object

Definition at line 388 of file Abstract.php.

{
if (is_array($constraint)) {
foreach ($constraint as $name => $def) {
$this->_table->addCheckConstraint($def, $name);
}
} else {
$this->_table->addCheckConstraint($constraint, $name);
}
return $this;
}
Doctrine_Record::cleanData ( $data)

cleanData leaves the $data array only with values whose key is a field inside this record and returns the values that were removed from $data. Also converts any values of 'null' to objects of type Doctrine_Null.

Parameters
array$datadata array to be cleaned
Returns
array values cleaned from data

Definition at line 712 of file Record.php.

{
$tmp = $data;
$data = array();
foreach ($this->getTable()->getFieldNames() as $fieldName) {
if (isset($tmp[$fieldName])) {
$data[$fieldName] = $tmp[$fieldName];
} else if (array_key_exists($fieldName, $tmp)) {
$data[$fieldName] = null;
} else if ( !isset($this->_data[$fieldName])) {
$data[$fieldName] = self::$_null;
}
unset($tmp[$fieldName]);
}
return $tmp;
}
Doctrine_Record::clearAccessor (   $fieldName)

clears the accessor for a field name

Parameters
string$fieldName
Returns
void

Definition at line 1229 of file Record.php.

{
$componentName = $this->_table->getComponentName();
unset(self::$_customAccessors[$componentName][$fieldName]);
}
Doctrine_Record::clearInvokedSaveHooks ( )

makes all the already used save hooks available again

Definition at line 368 of file Record.php.

{
$this->_invokedSaveHooks = array();
}
Doctrine_Record::clearMutator (   $fieldName)

clears the custom mutator for a field name

Parameters
string$fieldName
Returns
void

Definition at line 1298 of file Record.php.

{
$componentName = $this->_table->getComponentName();
unset(self::$_customMutators[$componentName][$fieldName]);
}
Doctrine_Record::clearRelated (   $name = null)

Clear a related reference or all references

Parameters
string$nameThe relationship reference to clear
Returns
void

Definition at line 1060 of file Record.php.

{
if (is_null($name)) {
$this->_references = array();
} else {
unset($this->_references[$name]);
}
}
Doctrine_Record::columnCount ( )

alias for

See Also
count()
Returns
integer the number of columns in this record

Definition at line 1879 of file Record.php.

{
return $this->count();
}
Doctrine_Record::construct ( )

construct Empty template method to provide concrete Record classes with the possibility to hook into the constructor procedure

Returns
void

Definition at line 313 of file Record.php.

{ }
Doctrine_Record::contains (   $fieldName)

test whether a field (column, mapped value, related component, accessor) is accessible by

See Also
get()
Parameters
string$fieldName
Returns
boolean

Definition at line 1631 of file Record.php.

{
if (array_key_exists($fieldName, $this->_data)) {
// this also returns true if the field is a Doctrine_Null.
// imho this is not correct behavior.
return true;
}
if (isset($this->_id[$fieldName])) {
return true;
}
if (isset($this->_values[$fieldName])) {
return true;
}
if (isset($this->_references[$fieldName]) &&
$this->_references[$fieldName] !== self::$_null) {
return true;
}
return false;
}
Doctrine_Record::copy (   $deep = false)

generates a copy of this object. Returns an instance of the same class of $this.

Parameters
boolean$deepwhether to duplicates the objects targeted by the relations
Returns
Doctrine_Record

Definition at line 2191 of file Record.php.

{
$data = $this->_data;
$idtype = $this->_table->getIdentifierType();
$id = $this->_table->getIdentifier();
unset($data[$id]);
}
$ret = $this->_table->create($data);
$modified = array();
foreach ($data as $key => $val) {
if ( ! ($val instanceof Doctrine_Null)) {
$ret->_modified[] = $key;
}
}
if ($deep) {
foreach ($this->_references as $key => $value) {
if ($value instanceof Doctrine_Collection) {
foreach ($value as $valueKey => $record) {
$ret->{$key}[$valueKey] = $record->copy($deep);
}
} else if ($value instanceof Doctrine_Record) {
$ret->set($key, $value->copy($deep));
}
}
}
return $ret;
}
Doctrine_Record::coreSetRelated (   $name,
  $value 
)

Places a related component in the object graph.

This method inserts a related component instance in this record relations, populating the foreign keys accordingly.

Parameters
string$namerelated component alias in the relation
Doctrine_Record | Doctrine_Collection$valueobject to be linked as a related component
Todo:
Refactor. What about composite keys?

Definition at line 1569 of file Record.php.

{
$rel = $this->_table->getRelation($name);
if ($value === null) {
$value = self::$_null;
}
// one-to-many or one-to-one relation
if ($rel instanceof Doctrine_Relation_ForeignKey || $rel instanceof Doctrine_Relation_LocalKey) {
if ( ! $rel->isOneToOne()) {
// one-to-many relation found
if ( ! ($value instanceof Doctrine_Collection)) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine_Core::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references.");
}
if (isset($this->_references[$name])) {
$this->_references[$name]->setData($value->getData());
return $this;
}
} else {
$localFieldName = $this->_table->getFieldName($rel->getLocal());
if ($value !== self::$_null) {
$relatedTable = $rel->getTable();
$foreignFieldName = $relatedTable->getFieldName($rel->getForeign());
}
// one-to-one relation found
if ( ! ($value instanceof Doctrine_Record) && ! ($value instanceof Doctrine_Null)) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine_Core::set(), second argument should be an instance of Doctrine_Record or Doctrine_Null when setting one-to-one references.");
}
if ($rel instanceof Doctrine_Relation_LocalKey) {
if ($value !== self::$_null && ! empty($foreignFieldName) && $foreignFieldName != $value->getTable()->getIdentifier()) {
$this->set($localFieldName, $value->rawGet($foreignFieldName), false);
} else {
// FIX: Ticket #1280 fits in this situation
$this->set($localFieldName, $value, false);
}
} elseif ($value !== self::$_null) {
// We should only be able to reach $foreignFieldName if we have a Doctrine_Record on hands
$value->set($foreignFieldName, $this, false);
}
}
} else if ($rel instanceof Doctrine_Relation_Association) {
// join table relation found
if ( ! ($value instanceof Doctrine_Collection)) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine_Core::set(), second argument should be an instance of Doctrine_Collection when setting many-to-many references.");
}
}
$this->_references[$name] = $value;
}
Doctrine_Record::count ( )

implements Countable interface

Returns
integer the number of columns in this record

Definition at line 1869 of file Record.php.

{
return count($this->_data);
}
Doctrine_Record::delete ( Doctrine_Connection  $conn = null)

deletes this data access object and all the related composites this operation is isolated by a transaction

this event can be listened by the onPreDelete and onDelete listeners

Returns
boolean true if successful

Definition at line 2177 of file Record.php.

{
if ($conn == null) {
$conn = $this->_table->getConnection();
}
return $conn->unitOfWork->delete($this);
}
Doctrine_Record::deleteNode ( )

used to delete node from tree - MUST BE USE TO DELETE RECORD IF TABLE ACTS AS TREE

Definition at line 2665 of file Record.php.

{
$this->getNode()->delete();
}
Doctrine_Record::errorStack (   $stack = null)

assigns the ErrorStack or returns it if called without parameters

Parameters
Doctrine_Validator_ErrorStackerrorStack to be assigned for this record
Returns
void|Doctrine_Validator_ErrorStack returns the errorStack associated with this record

Definition at line 646 of file Record.php.

{
if ($stack !== null) {
if ( ! ($stack instanceof Doctrine_Validator_ErrorStack)) {
throw new Doctrine_Record_Exception('Argument should be an instance of Doctrine_Validator_ErrorStack.');
}
$this->_errorStack = $stack;
} else {
return $this->getErrorStack();
}
}
Doctrine_Record::exists ( )

returns true if this record is saved in the database, otherwise false (it is transient)

Returns
boolean

Definition at line 2103 of file Record.php.

{
return ($this->_state !== Doctrine_Record::STATE_TCLEAN &&
$this->_state !== Doctrine_Record::STATE_TDIRTY &&
$this->_state !== Doctrine_Record::STATE_TLOCKED &&
$this->_state !== null);
}
Doctrine_Record::exportTo (   $type,
  $deep = true 
)

exports instance to a chosen format

Parameters
string$typeformat type: array, xml, yml, json
string$deepwhether or not to export all relationships
Returns
string representation as $type format. Array is $type is array

Definition at line 2073 of file Record.php.

{
if ($type == 'array') {
return $this->toArray($deep);
} else {
return Doctrine_Parser::dump($this->toArray($deep, true), $type);
}
}
Doctrine_Record::free (   $deep = false)

Helps freeing the memory occupied by the entity. Cuts all references the entity has to other entities and removes the entity from the instance pool. Note: The entity is no longer useable after free() has been called. Any operations done with the entity afterwards can lead to unpredictable results.

Parameters
boolean$deepwhether to free also the related components

Definition at line 2678 of file Record.php.

{
if ($this->_state != self::STATE_LOCKED && $this->_state != self::STATE_TLOCKED) {
$this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED;
$this->_table->getRepository()->evict($this->_oid);
$this->_table->removeRecord($this);
$this->_data = array();
$this->_id = array();
if ($deep) {
foreach ($this->_references as $name => $reference) {
if ( ! ($reference instanceof Doctrine_Null)) {
$reference->free($deep);
}
}
}
$this->_references = array();
}
}
Doctrine_Record::fromArray ( array  $array,
  $deep = true 
)

imports data from a php array

string $array array of data, see link for documentation bool $deep whether or not to act on relations void

Definition at line 1970 of file Record.php.

{
$refresh = false;
foreach ($array as $key => $value) {
if ($key == '_identifier') {
$refresh = true;
$this->assignIdentifier($value);
continue;
}
if ($deep && $this->getTable()->hasRelation($key)) {
if ( ! $this->$key) {
$this->refreshRelated($key);
}
if (is_array($value)) {
if (isset($value[0]) && ! is_array($value[0])) {
$this->unlink($key, array(), false);
$this->link($key, $value, false);
} else {
$this->$key->fromArray($value, $deep);
}
}
} else if ($this->getTable()->hasField($key) || array_key_exists($key, $this->_values)) {
$this->set($key, $value);
} else {
$method = 'set' . Doctrine_Inflector::classify($key);
try {
if (is_callable(array($this, $method))) {
$this->$method($value);
}
} catch (Doctrine_Record_Exception $e) {}
}
}
if ($refresh) {
$this->refresh();
}
}
Doctrine_Access::get (   $offset)
inherited

Return the element with the specified offset

Parameters
mixed$offsetThe offset to return
Returns
mixed

Definition at line 165 of file Access.php.

{
throw new Doctrine_Exception('Get is not supported for ' . get_class($this));
}
Doctrine_Record::get (   $fieldName,
  $load = true 
)

returns a value of a property or a related component

Parameters
mixed$fieldNamename of the property or related component
boolean$loadwhether or not to invoke the loading procedure
Exceptions
Doctrine_Record_Exceptionif trying to get a value of unknown property / related component
Returns
mixed

Definition at line 1336 of file Record.php.

{
if ($this->_table->getAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE) || $this->hasAccessor($fieldName)) {
$componentName = $this->_table->getComponentName();
$accessor = $this->hasAccessor($fieldName)
? $this->getAccessor($fieldName)
: 'get' . Doctrine_Inflector::classify($fieldName);
if ($this->hasAccessor($fieldName) || method_exists($this, $accessor)) {
$this->hasAccessor($fieldName, $accessor);
return $this->$accessor($load, $fieldName);
}
}
return $this->_get($fieldName, $load);
}
Doctrine_Record::getAccessor (   $fieldName)

gets the custom accessor for a field name

Parameters
string$fieldName
Returns
string $accessor

Definition at line 1241 of file Record.php.

{
if ($this->hasAccessor($fieldName)) {
$componentName = $this->_table->getComponentName();
return self::$_customAccessors[$componentName][$fieldName];
}
}
Doctrine_Record::getAccessors ( )

gets all accessors for this component instance

Returns
array $accessors

Definition at line 1254 of file Record.php.

{
$componentName = $this->_table->getComponentName();
return isset(self::$_customAccessors[$componentName]) ? self::$_customAccessors[$componentName] : array();
}
Doctrine_Record::getData ( )

return all the internal data (columns)

Returns
array an array containing all the properties

Definition at line 1117 of file Record.php.

{
return $this->_data;
}
Doctrine_Record::getErrorStack ( )

retrieves the ErrorStack. To be called after a failed validation attempt (

See Also
isValid()).
Returns
Doctrine_Validator_ErrorStack returns the errorStack associated with this record

Definition at line 631 of file Record.php.

{
if ( ! $this->_errorStack) {
$this->_errorStack = new Doctrine_Validator_ErrorStack(get_class($this));
}
return $this->_errorStack;
}
Doctrine_Record::getErrorStackAsString ( )

Get the record error stack as a human readable string. Useful for outputting errors to user via web browser

Returns
string $message

Definition at line 609 of file Record.php.

{
$errorStack = $this->getErrorStack();
if (count($errorStack)) {
$message = sprintf("Validation failed in class %s\n\n", get_class($this));
$message .= " " . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " had validation error" . (count($errorStack) > 1 ? 's' : null) . ":\n\n";
foreach ($errorStack as $field => $errors) {
$message .= " * " . count($errors) . " validator" . (count($errors) > 1 ? 's' : null) . " failed on $field (" . implode(", ", $errors) . ")\n";
}
return $message;
} else {
return false;
}
}
Doctrine_Record::getIncremented ( )
final

returns the value of autoincremented primary key of this object (if any)

Returns
integer
Todo:
Better name?

Definition at line 2274 of file Record.php.

{
$id = current($this->_id);
if ($id === false) {
return null;
}
return $id;
}
Doctrine_Record::getIterator ( )

implements IteratorAggregate interface

Returns
Doctrine_Record_Iterator iterator through data

Definition at line 2164 of file Record.php.

{
return new Doctrine_Record_Iterator($this);
}
Doctrine_Record::getLast ( )

getLast this method is used internally by Doctrine_Query it is needed to provide compatibility between records and collections

Returns
Doctrine_Record

Definition at line 2292 of file Record.php.

{
return $this;
}
Doctrine_Record::getLastModified (   $old = false)

returns an array of the modified fields from the last transaction.

Parameters
boolean$oldpick the old values (instead of the new ones)
Returns
array

Definition at line 1794 of file Record.php.

{
return $this->getModified($old, true);
}
Doctrine_Record_Abstract::getListener ( )
inherited

getListener

Returns
Doctrine_EventListener_Interface|Doctrine_Overloadable

Definition at line 79 of file Abstract.php.

{
return $this->_table->getRecordListener();
}
Doctrine_Locator_Injectable::getLocator ( )
inherited

getLocator returns the locator associated with this object

if there are no locator locally associated then this method tries to fetch the current global locator

Returns
Doctrine_Locator

Definition at line 75 of file Injectable.php.

{
if ( ! isset($this->_locator)) {
$this->_locator = Doctrine_Locator::instance();
}
return $this->_locator;
}
Doctrine_Record::getModified (   $old = false,
  $last = false 
)

retrieves an array of modified fields and associated new values.

Parameters
boolean$oldpick the old values (instead of the new ones)
boolean$lastpick only lastModified values (
See Also
getLastModified())
Returns
array $a

Definition at line 1771 of file Record.php.

{
$a = array();
$modified = $last ? $this->_lastModified:$this->_modified;
foreach ($modified as $fieldName) {
if ($old) {
$a[$fieldName] = isset($this->_oldValues[$fieldName])
? $this->_oldValues[$fieldName]
: $this->getTable()->getDefaultValueOf($fieldName);
} else {
$a[$fieldName] = $this->_data[$fieldName];
}
}
return $a;
}
Doctrine_Record::getMutator (   $fieldName)

gets the custom mutator for a field name

Parameters
string$fieldname
Returns
string

Definition at line 1284 of file Record.php.

{
if ($this->hasMutator($fieldName)) {
$componentName = $this->_table->getComponentName();
return self::$_customMutators[$componentName][$fieldName];
}
}
Doctrine_Record::getMutators ( )

gets all custom mutators for this component instance

Returns
array $mutators

Definition at line 1309 of file Record.php.

{
$componentName = $this->_table->getComponentName();
return self::$_customMutators[$componentName];
}
Doctrine_Record::getNode ( )

getter for node associated with this record

Returns
Doctrine_Node false if component is not a Tree

Definition at line 2397 of file Record.php.

{
if ( ! $this->_table->isTree()) {
return false;
}
if ( ! isset($this->_node)) {
$this->_node = Doctrine_Node::factory($this,
$this->getTable()->getOption('treeImpl'),
$this->getTable()->getOption('treeOptions')
);
}
return $this->_node;
}
static Doctrine_Locator_Injectable::getNullObject ( )
staticinherited

getNullObject returns the null object associated with this object

Returns
Doctrine_Null

Definition at line 145 of file Injectable.php.

{
return self::$_null;
}
Doctrine_Record::getOid ( )
See Also
$_oid;
Returns
integer the object identifier

Definition at line 321 of file Record.php.

{
return $this->_oid;
}
Doctrine_Record::getPendingDeletes ( )

returns Doctrine_Record instances which need to be deleted on save

Returns
array

Definition at line 1677 of file Record.php.

{
return $this->_pendingDeletes;
}
Doctrine_Record::getPendingUnlinks ( )

returns Doctrine_Record instances which need to be unlinked (deleting the relation) on save

Returns
array $pendingUnlinks

Definition at line 1687 of file Record.php.

Doctrine_Record::getPrepared ( array  $array = array())

Retrieves data prepared for a sql transaction.

Returns an array of modified fields and values with data preparation; adds column aggregation inheritance and converts Records into primary key values.

Parameters
array$array
Returns
array
Todo:
What about a little bit more expressive name? getPreparedData?
TODO:

if ($this->_data[$v] === null) { throw new Doctrine_Record_Exception('Unexpected null value.'); }

Definition at line 1810 of file Record.php.

{
$a = array();
if (empty($array)) {
$modifiedFields = $this->_modified;
}
foreach ($modifiedFields as $field) {
$type = $this->_table->getTypeOf($field);
if ($this->_data[$field] === self::$_null) {
$a[$field] = null;
continue;
}
switch ($type) {
case 'array':
case 'object':
$a[$field] = serialize($this->_data[$field]);
break;
case 'gzip':
$a[$field] = gzcompress($this->_data[$field],5);
break;
case 'boolean':
$a[$field] = $this->getTable()->getConnection()->convertBooleans($this->_data[$field]);
break;
case 'set':
if (is_array($this->_data[$field])) {
$a[$field] = implode(',', $this->_data[$field]);
} else {
$a[$field] = $this->_data[$field];
}
break;
default:
if ($this->_data[$field] instanceof Doctrine_Record) {
$a[$field] = $this->_data[$field]->getIncremented();
if ($a[$field] !== null) {
$this->_data[$field] = $a[$field];
}
} else {
$a[$field] = $this->_data[$field];
}
/** TODO:
if ($this->_data[$v] === null) {
throw new Doctrine_Record_Exception('Unexpected null value.');
}
*/
}
}
return $a;
}
Doctrine_Record::getReferences ( )

get all related components

Returns
array various Doctrine_Collection or Doctrine_Record instances

Definition at line 2338 of file Record.php.

{
return $this->_references;
}
Doctrine_Record::getTable ( )

returns the table object for this record.

Returns
Doctrine_Table a Doctrine_Table object

Definition at line 1107 of file Record.php.

{
return $this->_table;
}
Doctrine_Record::hasAccessor (   $fieldName,
  $accessor = null 
)

sets a fieldname to have a custom accessor or check if a field has a custom accessor defined (when called without $accessor parameter).

Parameters
string$fieldName
string$accessor
Returns
boolean

Definition at line 1213 of file Record.php.

{
$componentName = $this->_table->getComponentName();
if ($accessor) {
self::$_customAccessors[$componentName][$fieldName] = $accessor;
} else {
return (isset(self::$_customAccessors[$componentName][$fieldName]) && self::$_customAccessors[$componentName][$fieldName]);
}
}
Doctrine_Record::hasAccessorMutator (   $fieldName,
  $accessor,
  $mutator 
)

Set a fieldname to have a custom accessor and mutator

Parameters
string$fieldname
string$accessor
string$mutator

Definition at line 1322 of file Record.php.

{
$this->hasAccessor($fieldName, $accessor);
$this->hasMutator($fieldName, $mutator);
}
Doctrine_Record_Abstract::hasColumn (   $name,
  $type = null,
  $length = null,
  $options = array() 
)
inherited

Sets a column definition

Parameters
string$name
string$type
integer$length
mixed$options
Returns
void

Definition at line 260 of file Abstract.php.

{
$this->_table->setColumn($name, $type, $length, $options);
}
Doctrine_Record_Abstract::hasColumns ( array  $definitions)
inherited

Set multiple column definitions at once

Parameters
array$definitions
Returns
void

Definition at line 271 of file Abstract.php.

{
foreach ($definitions as $name => $options) {
$length = isset($options['length']) ? $options['length']:null;
$this->hasColumn($name, $options['type'], $length, $options);
}
}
Doctrine_Record_Abstract::hasMany ( )
inherited

Binds One-to-Many / Many-to-Many aggregate relation

Parameters
string$componentNamethe name of the related component
string$optionsrelation options
See Also
Doctrine_Relation::_$definition
Returns
Doctrine_Record this object

Definition at line 244 of file Abstract.php.

{
$this->_table->bind(func_get_args(), Doctrine_Relation::MANY);
return $this;
}
Doctrine_Record::hasMappedValue (   $name)

Tests whether a mapped value exists

Parameters
string$namethe name of the property
Returns
boolean

Definition at line 1426 of file Record.php.

{
return array_key_exists($name, $this->_values);
}
Doctrine_Record::hasMutator (   $fieldName,
  $mutator = null 
)

sets a fieldname to have a custom mutator or check if a field has a custom mutator defined (when called without the $mutator parameter)

Parameters
string$fieldName
string$mutator
Returns
boolean

Definition at line 1268 of file Record.php.

{
$componentName = $this->_table->getComponentName();
if ($mutator) {
self::$_customMutators[$componentName][$fieldName] = $mutator;
} else {
return (isset(self::$_customMutators[$componentName][$fieldName]) && self::$_customMutators[$componentName][$fieldName]);
}
}
Doctrine_Record_Abstract::hasOne ( )
inherited

Binds One-to-One aggregate relation

Parameters
string$componentNamethe name of the related component
string$optionsrelation options
See Also
Doctrine_Relation::_$definition
Returns
Doctrine_Record this object

Definition at line 229 of file Abstract.php.

{
$this->_table->bind(func_get_args(), Doctrine_Relation::ONE);
return $this;
}
Doctrine_Record::hasReference (   $name)

tests whether a relation is set

Parameters
string$namerelation alias
Returns
boolean

Definition at line 2302 of file Record.php.

{
return isset($this->_references[$name]);
}
Doctrine_Record::hasRelation (   $fieldName)

checks existence of properties and related components

Parameters
mixed$fieldNamename of the property or reference
Returns
boolean

Definition at line 2152 of file Record.php.

{
if (isset($this->_data[$fieldName]) || isset($this->_id[$fieldName])) {
return true;
}
return $this->_table->hasRelation($fieldName);
}
Doctrine_Record::hydrate ( array  $data,
  $overwriteLocalChanges = true 
)

hydrate hydrates this object from given array

Parameters
array$data
boolean$overwriteLocalChangeswhether to overwrite the unsaved (dirty) data
Returns
void

Definition at line 739 of file Record.php.

{
if ($overwriteLocalChanges) {
$this->_values = array_merge($this->_values, $this->cleanData($data));
$this->_data = array_merge($this->_data, $data);
$this->_modified = array();
$this->_oldValues = array();
} else {
$this->_values = array_merge($this->cleanData($data), $this->_values);
$this->_data = array_merge($data, $this->_data);
}
if (!$this->isModified() && $this->isInProxyState()) {
$this->_state = self::STATE_PROXY;
}
}
integer $oid object identifier each Record object has a unique object Doctrine_Record::identifier ( )

returns the primary keys of this object

Returns
array

Definition at line 2263 of file Record.php.

{
return $this->_id;
}
Doctrine_Record::importFrom (   $type,
  $data,
  $deep = true 
)

imports data from a chosen format in the current instance

Parameters
string$typeFormat type: xml, yml, json
string$dataData to be parsed and imported
Returns
void

Definition at line 2089 of file Record.php.

{
if ($type == 'array') {
return $this->fromArray($data, $deep);
} else {
return $this->fromArray(Doctrine_Parser::load($data, $type), $deep);
}
}
Doctrine_Record_Abstract::index (   $name,
array  $definition = array() 
)
inherited

index defines or retrieves an index if the second parameter is set this method defines an index if not this method retrieves index named $name

Parameters
string$namethe name of the index
array$definitionthe definition array
Returns
mixed

Definition at line 107 of file Abstract.php.

{
if ( ! $definition) {
return $this->_table->getIndex($name);
} else {
return $this->_table->addIndex($name, $definition);
}
}
static Doctrine_Locator_Injectable::initNullObject ( Doctrine_Null  $null)
staticinherited

initNullObject initializes the null object

Parameters
Doctrine_Null$null
Returns
void

Definition at line 134 of file Injectable.php.

{
self::$_null = $null;
}
Doctrine_Record::invokeSaveHooks (   $when,
  $type,
  $event = null 
)

calls a subclass hook. Idempotent until

See Also
clearInvokedSaveHooks() is called.

$this->invokeSaveHooks('pre', 'save');

Parameters
string$when'post' or 'pre'
string$typeserialize, unserialize, save, delete, update, insert, validate, dqlSelect, dqlDelete, hydrate
Doctrine_Event$eventevent raised
Returns
Doctrine_Event the event generated using the type, if not specified

Definition at line 343 of file Record.php.

{
$func = $when . ucfirst($type);
if (is_null($event)) {
$constant = constant('Doctrine_Event::RECORD_' . strtoupper($type));
//echo $func . " - " . 'Doctrine_Event::RECORD_' . strtoupper($type) . "\n";
$event = new Doctrine_Event($this, $constant);
}
if ( ! isset($this->_invokedSaveHooks[$func])) {
$this->$func($event);
$this->getTable()->getRecordListener()->$func($event);
$this->_invokedSaveHooks[$func] = $event;
} else {
$event = $this->_invokedSaveHooks[$func];
}
return $event;
}
Doctrine_Record::isInProxyState ( )

indicates whether record has any not loaded fields

Returns
boolean

Definition at line 1191 of file Record.php.

{
$count = 0;
foreach ($this->_data as $value) {
if ($value !== self::$_null) {
$count++;
}
}
if ($count < $this->_table->getColumnCount()) {
return true;
}
return false;
}
Doctrine_Record::isModified (   $deep = false)

returns true if this record was modified, otherwise false

Parameters
boolean$deepwhether to process also the relations for changes
Returns
boolean

Definition at line 2117 of file Record.php.

{
$modified = ($this->_state === Doctrine_Record::STATE_DIRTY ||
$this->_state === Doctrine_Record::STATE_TDIRTY);
if ( ! $modified && $deep) {
if ($this->_state == self::STATE_LOCKED || $this->_state == self::STATE_TLOCKED) {
return false;
}
$stateBeforeLock = $this->_state;
$this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED;
foreach ($this->_references as $reference) {
if ($reference instanceof Doctrine_Record) {
if ($modified = $reference->isModified($deep)) {
break;
}
} else if ($reference instanceof Doctrine_Collection) {
foreach ($reference as $record) {
if ($modified = $record->isModified($deep)) {
break 2;
}
}
}
}
$this->_state = $stateBeforeLock;
}
return $modified;
}
Doctrine_Record::isValid (   $deep = false,
  $hooks = true 
)

tests validity of the record using the current data.

Parameters
boolean$deeprun the validation process on the relations
boolean$hooksinvoke save hooks before start
Returns
boolean whether or not this record is valid

Definition at line 380 of file Record.php.

{
if ( ! $this->_table->getAttribute(Doctrine_Core::ATTR_VALIDATE)) {
return true;
}
if ($this->_state == self::STATE_LOCKED || $this->_state == self::STATE_TLOCKED) {
return true;
}
if ($hooks) {
$this->invokeSaveHooks('pre', 'save');
$this->invokeSaveHooks('pre', $this->exists() ? 'update' : 'insert');
}
// Clear the stack from any previous errors.
$this->getErrorStack()->clear();
// Run validation process
$event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE);
$this->preValidate($event);
$this->getTable()->getRecordListener()->preValidate($event);
if ( ! $event->skipOperation) {
$validator = new Doctrine_Validator();
$validator->validateRecord($this);
$this->validate();
if ($this->_state == self::STATE_TDIRTY || $this->_state == self::STATE_TCLEAN) {
$this->validateOnInsert();
} else {
$this->validateOnUpdate();
}
}
$this->getTable()->getRecordListener()->postValidate($event);
$this->postValidate($event);
$valid = $this->getErrorStack()->count() == 0 ? true : false;
if ($valid && $deep) {
$stateBeforeLock = $this->_state;
$this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED;
foreach ($this->_references as $reference) {
if ($reference instanceof Doctrine_Record) {
if ( ! $valid = $reference->isValid($deep)) {
break;
}
} else if ($reference instanceof Doctrine_Collection) {
foreach ($reference as $record) {
if ( ! $valid = $record->isValid($deep)) {
break;
}
}
}
}
$this->_state = $stateBeforeLock;
}
return $valid;
}
Doctrine_Record::link (   $alias,
  $ids,
  $now = false 
)

creates links from this record to given records

Parameters
string$aliasrelated component alias
array$idsthe identifiers of the related records
boolean$nowwether or not to execute now or set pending
Returns
Doctrine_Record this object (fluent interface)

Definition at line 2511 of file Record.php.

{
$ids = (array) $ids;
if ( ! count($ids)) {
return $this;
}
if ( ! $this->exists() || $now === false) {
$relTable = $this->getTable()->getRelation($alias)->getTable();
$records = $relTable->createQuery()
->whereIn($relTable->getIdentifier(), $ids)
->execute();
foreach ($records as $record) {
if ($this->$alias instanceof Doctrine_Record) {
$this->set($alias, $record);
} else {
if ($c = $this->get($alias)) {
$c->add($record);
} else {
$this->set($alias, $record);
}
}
}
foreach ($ids as $id) {
if (isset($this->_pendingUnlinks[$alias][$id])) {
unset($this->_pendingUnlinks[$alias][$id]);
}
}
return $this;
} else {
return $this->linkInDb($alias, $ids);
}
}
Doctrine_Record::linkInDb (   $alias,
  $ids 
)

creates links from this record to given records now, querying the db

Parameters
string$aliasrelated component alias
array$idsthe identifiers of the related records
Returns
Doctrine_Record this object (fluent interface)

Definition at line 2556 of file Record.php.

{
$identifier = array_values($this->identifier());
$identifier = array_shift($identifier);
$rel = $this->getTable()->getRelation($alias);
if ($rel instanceof Doctrine_Relation_Association) {
$modelClassName = $rel->getAssociationTable()->getComponentName();
$localFieldName = $rel->getLocalFieldName();
$localFieldDef = $rel->getAssociationTable()->getColumnDefinition($localFieldName);
if ($localFieldDef['type'] == 'integer') {
$identifier = (integer) $identifier;
}
$foreignFieldName = $rel->getForeignFieldName();
$foreignFieldDef = $rel->getAssociationTable()->getColumnDefinition($foreignFieldName);
if ($foreignFieldDef['type'] == 'integer') {
foreach ($ids as $i => $id) {
$ids[$i] = (integer) $id;
}
}
foreach ($ids as $id) {
$record = new $modelClassName;
$record[$localFieldName] = $identifier;
$record[$foreignFieldName] = $id;
$record->save();
}
} else if ($rel instanceof Doctrine_Relation_ForeignKey) {
$q = $rel->getTable()
->createQuery()
->update()
->set($rel->getForeign(), '?', array_values($this->identifier()));
if (count($ids) > 0) {
$q->whereIn($rel->getTable()->getIdentifier(), $ids);
}
$q->execute();
} else if ($rel instanceof Doctrine_Relation_LocalKey) {
$q = $this->getTable()
->createQuery()
->update()
->set($rel->getLocalFieldName(), '?', $ids);
if (count($ids) > 0) {
$q->whereIn($rel->getTable()->getIdentifier(), array_values($this->identifier()));
}
$q->execute();
}
return $this;
}
Doctrine_Record::load ( array  $data = array())

loads all the uninitialized properties from the database. Used to move a record from PROXY to CLEAN/DIRTY state.

Parameters
array$dataoverwriting data to load in the record. Instance is hydrated from the table if not specified.
Returns
boolean

Definition at line 1149 of file Record.php.

{
// only load the data from database if the Doctrine_Record is in proxy state
if ($this->exists() && $this->isInProxyState()) {
$id = $this->identifier();
if ( ! is_array($id)) {
$id = array($id);
}
if (empty($id)) {
return false;
}
$table = $this->getTable();
$data = empty($data) ? $table->find($id, Doctrine_Core::HYDRATE_ARRAY) : $data;
if (is_array($data)) {
foreach ($data as $field => $value) {
if ($table->hasField($field) && ( ! array_key_exists($field, $this->_data) || $this->_data[$field] === self::$_null)) {
$this->_data[$field] = $value;
}
}
}
if ($this->isModified()) {
} else if (!$this->isInProxyState()) {
}
return true;
}
return false;
}
Doctrine_Record::loadReference (   $name)

loadReference loads a related component

Exceptions
Doctrine_Table_Exceptionif trying to load an unknown related component
Parameters
string$namealias of the relation
Returns
void

Definition at line 2362 of file Record.php.

{
$rel = $this->_table->getRelation($name);
$this->_references[$name] = $rel->fetchRelatedFor($this);
}
Doctrine_Locator_Injectable::locate (   $name)
inherited

locate locates a resource by given name and returns it

if the resource cannot be found locally this method tries to use the global locator for finding the resource

See Also
Doctrine_Locator::locate()
Exceptions
Doctrine_Locator_Exceptionif the resource could not be found
Parameters
string$namethe name of the resource
Returns
mixed the located resource

Definition at line 96 of file Injectable.php.

{
if (isset($this->_resources[$name])) {
if (is_object($this->_resources[$name])) {
return $this->_resources[$name];
} else {
// get the name of the concrete implementation
$concreteImpl = $this->_resources[$name];
return $this->getLocator()->locate($concreteImpl);
}
} else {
return $this->getLocator()->locate($name);
}
}
Doctrine_Record::mapValue (   $name,
  $value = null 
)

sets a value that will be managed as if it were a field by magic accessor and mutators,

See Also
get() and
set(). Normally used by Doctrine for the mapping of aggregate values.
Parameters
string$namethe name of the mapped value
mixed$valuemixed value to be mapped
Returns
void

Definition at line 1415 of file Record.php.

{
$this->_values[$name] = $value;
}
Doctrine_Record::merge (   $data,
  $deep = true 
)

merges this record with an array of values or with another existing instance of this object

See Also
fromArray() string $array array of data to merge, see link for documentation bool $deep whether or not to merge relations void

Definition at line 1951 of file Record.php.

{
if ($data instanceof $this) {
$array = $data->toArray($deep);
} else if (is_array($data)) {
$array = $data;
}
return $this->fromArray($array, $deep);
}
Doctrine_Record::obtainReference (   $name)

gets a related component and fails if it does not exist

Parameters
string$name
Exceptions
Doctrine_Record_Exceptionif trying to get an unknown related component

Definition at line 2326 of file Record.php.

{
if (isset($this->_references[$name])) {
return $this->_references[$name];
}
throw new Doctrine_Record_Exception("Unknown reference $name");
}
Doctrine_Access::offsetExists (   $offset)
inherited

Check if an offset axists

Parameters
mixed$offset
Returns
boolean Whether or not this object contains $offset

Definition at line 103 of file Access.php.

{
return $this->contains($offset);
}
Doctrine_Access::offsetGet (   $offset)
inherited

An alias of get()

See Also
get, __get
Parameters
mixed$offset
Returns
mixed

Definition at line 115 of file Access.php.

{
return $this->get($offset);
}
Doctrine_Access::offsetSet (   $offset,
  $value 
)
inherited

Sets $offset to $value

See Also
set, __set
Parameters
mixed$offset
mixed$value
Returns
void

Definition at line 128 of file Access.php.

{
if ( ! isset($offset)) {
$this->add($value);
} else {
$this->set($offset, $value);
}
}
Doctrine_Access::offsetUnset (   $offset)
inherited

Unset a given offset

See Also
set, offsetSet, __set
Parameters
mixed$offset

Definition at line 143 of file Access.php.

{
return $this->remove($offset);
}
Doctrine_Record_Abstract::option (   $name,
  $value = null 
)
inherited

option sets or retrieves an option

See Also
Doctrine_Table::$options availible options
Parameters
mixed$namethe name of the option
mixed$valueoptions value
Returns
mixed

Definition at line 206 of file Abstract.php.

{
if ($value === null) {
if (is_array($name)) {
foreach ($name as $k => $v) {
$this->_table->setOption($k, $v);
}
} else {
return $this->_table->getOption($name);
}
} else {
$this->_table->setOption($name, $value);
}
}
Doctrine_Record::postDelete (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the deletion procedure.

Definition at line 519 of file Record.php.

{ }
Doctrine_Record::postHydrate (   $event)

Empty template method to provide Record classes with the ability to alter hydration after it runs

Definition at line 600 of file Record.php.

{ }
Doctrine_Record::postInsert (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the saving procedure only when the record is going to be inserted into the data store the first time.

Definition at line 551 of file Record.php.

{ }
Doctrine_Record::postSave (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the saving procedure.

Definition at line 505 of file Record.php.

{ }
Doctrine_Record::postSerialize (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the serializing procedure.

Definition at line 477 of file Record.php.

{ }
Doctrine_Record::postUnserialize (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the serializing procedure.

Definition at line 491 of file Record.php.

{ }
Doctrine_Record::postUpdate (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the saving procedure only when the record is going to be updated.

Definition at line 535 of file Record.php.

{ }
Doctrine_Record::postValidate (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the validation procedure.

Definition at line 565 of file Record.php.

{ }
Doctrine_Record::preDelete (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the deletion procedure.

Definition at line 512 of file Record.php.

{ }
Doctrine_Record::preDqlDelete (   $event)

Empty template method to provide Record classes with the ability to alter DQL delete queries at runtime

Definition at line 586 of file Record.php.

{ }
Doctrine_Record::preDqlSelect (   $event)

Empty template method to provide Record classes with the ability to alter DQL select queries at runtime

Definition at line 572 of file Record.php.

{ }
Doctrine_Record::preDqlUpdate (   $event)

Empty template method to provide Record classes with the ability to alter DQL update queries at runtime

Definition at line 579 of file Record.php.

{ }
Doctrine_Record::preHydrate (   $event)

Empty template method to provide Record classes with the ability to alter hydration before it runs

Definition at line 593 of file Record.php.

{ }
Doctrine_Record::preInsert (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the saving procedure only when the record is going to be inserted into the data store the first time.

Definition at line 543 of file Record.php.

{ }
Doctrine_Record::preSave (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the saving procedure.

Definition at line 498 of file Record.php.

{ }
Doctrine_Record::preSerialize (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the serializing procedure.

Definition at line 470 of file Record.php.

{ }
Doctrine_Record::preUnserialize (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the serializing procedure.

Definition at line 484 of file Record.php.

{ }
Doctrine_Record::preUpdate (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the saving procedure only when the record is going to be updated.

Definition at line 527 of file Record.php.

{ }
Doctrine_Record::preValidate (   $event)

Empty template method to provide concrete Record classes with the possibility to hook into the validation procedure. Useful for cleaning up data before validating it.

Definition at line 559 of file Record.php.

{ }
Doctrine_Record::rawGet (   $fieldName)

returns the value of a property (column). If the property is not yet loaded this method does NOT load it.

Parameters
$namename of the property
Exceptions
Doctrine_Record_Exceptionif trying to get an unknown property
Returns
mixed

Definition at line 1130 of file Record.php.

{
if ( ! array_key_exists($fieldName, $this->_data)) {
throw new Doctrine_Record_Exception('Unknown property '. $fieldName);
}
if ($this->_data[$fieldName] === self::$_null) {
return null;
}
return $this->_data[$fieldName];
}
Doctrine_Record::reference (   $name)

gets a related component

Parameters
string$name
Returns
Doctrine_Record|Doctrine_Collection

Definition at line 2313 of file Record.php.

{
if (isset($this->_references[$name])) {
return $this->_references[$name];
}
}
Doctrine_Record::refresh (   $deep = false)

refresh refresh internal data from the database

Parameters
bool$deepIf true, fetch also current relations. Caution: this deletes any aggregated values you may have queried beforee
Exceptions
Doctrine_Record_ExceptionWhen the refresh operation fails (when the database row this record represents does not exist anymore)
Returns
boolean

Definition at line 967 of file Record.php.

{
$id = $this->identifier();
if ( ! is_array($id)) {
$id = array($id);
}
if (empty($id)) {
return false;
}
$id = array_values($id);
$overwrite = $this->getTable()->getAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE);
$this->getTable()->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, true);
if ($deep) {
$query = $this->getTable()->createQuery();
foreach (array_keys($this->_references) as $name) {
$query->leftJoin(get_class($this) . '.' . $name);
}
$query->where(implode(' = ? AND ', (array)$this->getTable()->getIdentifier()) . ' = ?');
$this->clearRelated();
$record = $query->fetchOne($id);
} else {
// Use HYDRATE_ARRAY to avoid clearing object relations
$record = $this->getTable()->find($id, Doctrine_Core::HYDRATE_ARRAY);
if ($record) {
$this->hydrate($record);
}
}
$this->getTable()->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, $overwrite);
if ($record === false) {
throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist.');
}
$this->_resetModified();
$this->prepareIdentifiers();
return $this;
}
Doctrine_Record::refreshRelated (   $name = null)

refresh refresh data of related objects from the database

Parameters
string$namename of a related component. if set, this method only refreshes the specified related component
Returns
Doctrine_Record this object

Definition at line 1021 of file Record.php.

{
if (is_null($name)) {
foreach ($this->_table->getRelations() as $rel) {
$alias = $rel->getAlias();
unset($this->_references[$alias]);
$reference = $rel->fetchRelatedFor($this);
if ($reference instanceof Doctrine_Collection) {
$this->_references[$alias] = $reference;
} else if ($reference instanceof Doctrine_Record) {
if ($reference->exists()) {
$this->_references[$alias] = $reference;
} else {
$reference->free();
}
}
}
} else {
unset($this->_references[$name]);
$rel = $this->_table->getRelation($name);
$reference = $rel->fetchRelatedFor($this);
if ($reference instanceof Doctrine_Collection) {
$this->_references[$name] = $reference;
} else if ($reference instanceof Doctrine_Record) {
if ($reference->exists()) {
$this->_references[$name] = $reference;
} else {
$reference->free();
}
}
}
}
Doctrine_Record::relatedExists (   $name)

Check if a related relationship exists. Will lazily load the relationship in order to check. If the reference didn't already exist and it doesn't exist in the database, the related reference will be cleared immediately.

Parameters
string$name
Returns
boolean Whether or not the related relationship exists

Definition at line 1077 of file Record.php.

{
if ($this->hasReference($name) && $this->_references[$name] !== self::$_null) {
return true;
}
$reference = $this->$name;
if ($reference instanceof Doctrine_Record) {
$exists = $reference->exists();
} elseif ($reference instanceof Doctrine_Collection) {
'You can only call relatedExists() on a relationship that '.
'returns an instance of Doctrine_Record'
);
} else {
$exists = false;
}
if (!$exists) {
$this->clearRelated($name);
}
return $exists;
}
Doctrine_Access::remove (   $offset)
inherited

Remove the element with the specified offset

Parameters
mixed$offsetThe offset to remove
Returns
boolean True if removed otherwise false

Definition at line 154 of file Access.php.

{
throw new Doctrine_Exception('Remove is not supported for ' . get_class($this));
}
Doctrine_Record::replace ( Doctrine_Connection  $conn = null)

executes a SQL REPLACE query. A REPLACE query is identical to a INSERT query, except that if there is already a row in the table with the same key field values, the REPLACE query just updates its values instead of inserting a new row.

The REPLACE type of query does not make part of the SQL standards. Since practically only MySQL and SQLIte implement it natively, this type of query isemulated through this method for other DBMS using standard types of queries inside a transaction to assure the atomicity of the operation.

Parameters
Doctrine_Connection$connoptional connection parameter
Exceptions
Doctrine_Connection_Exceptionif some of the key values was null
Doctrine_Connection_Exceptionif there were no key fields
Doctrine_Connection_Exceptionif something fails at database level
Returns
integer number of rows affected

Definition at line 1756 of file Record.php.

{
if ($conn === null) {
$conn = $this->_table->getConnection();
}
return $conn->unitOfWork->saveGraph($this, true);
}
Doctrine_Record::resetPendingUnlinks ( )

resets pending record unlinks

Returns
void

Definition at line 1697 of file Record.php.

{
$this->_pendingUnlinks = array();
}
Doctrine_Record::save ( Doctrine_Connection  $conn = null)

applies the changes made to this object into database this method is smart enough to know if any changes are made and whether to use INSERT or UPDATE statement

this method also saves the related components

Parameters
Doctrine_Connection$connoptional connection parameter
Exceptions
Exceptionif record is not valid and validation is active
Returns
void

Definition at line 1713 of file Record.php.

{
if ($conn === null) {
$conn = $this->_table->getConnection();
}
$conn->unitOfWork->saveGraph($this);
}
Doctrine_Record::serialize ( )

serialize this method is automatically called when an instance of Doctrine_Record is serialized

Returns
string

Definition at line 799 of file Record.php.

{
$event = new Doctrine_Event($this, Doctrine_Event::RECORD_SERIALIZE);
$this->preSerialize($event);
$this->getTable()->getRecordListener()->preSerialize($event);
$vars = get_object_vars($this);
if ( ! $this->serializeReferences()) {
unset($vars['_references']);
}
unset($vars['_table']);
unset($vars['_errorStack']);
unset($vars['_filter']);
unset($vars['_node']);
$data = $this->_data;
if ($this->exists()) {
$data = array_merge($data, $this->_id);
}
foreach ($data as $k => $v) {
if ($v instanceof Doctrine_Record && $this->_table->getTypeOf($k) != 'object') {
unset($vars['_data'][$k]);
} elseif ($v === self::$_null) {
unset($vars['_data'][$k]);
} else {
switch ($this->_table->getTypeOf($k)) {
case 'array':
case 'object':
$vars['_data'][$k] = serialize($vars['_data'][$k]);
break;
case 'gzip':
$vars['_data'][$k] = gzcompress($vars['_data'][$k]);
break;
case 'enum':
$vars['_data'][$k] = $this->_table->enumIndex($k, $vars['_data'][$k]);
break;
}
}
}
$str = serialize($vars);
$this->postSerialize($event);
$this->getTable()->getRecordListener()->postSerialize($event);
return $str;
}
Doctrine_Record::serializeReferences (   $bool = null)

Set whether or not to serialize references. This is used by caching since we want to serialize references when caching but not when just normally serializing a instance

Parameters
boolean$bool
Returns
boolean $bool

Definition at line 279 of file Record.php.

{
if ( ! is_null($bool)) {
$this->_serializeReferences = $bool;
}
return $this->_serializeReferences;
}
Doctrine_Access::set (   $offset,
  $value 
)
inherited

Set the offset to the value

Parameters
mixed$offsetThe offset to set
mixed$valueThe value to set the offset to

Definition at line 177 of file Access.php.

{
throw new Doctrine_Exception('Set is not supported for ' . get_class($this));
}
Doctrine_Record::set (   $fieldName,
  $value,
  $load = true 
)

alters mapped values, properties and related components.

Parameters
mixed$namename of the property or reference
mixed$valuevalue of the property or reference
boolean$loadwhether or not to refresh / load the uninitialized record data
Exceptions
Doctrine_Record_Exceptionif trying to set a value for unknown property / related component
Doctrine_Record_Exceptionif trying to set a value of wrong type for related component
Returns
Doctrine_Record

Definition at line 1443 of file Record.php.

{
if ($this->_table->getAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE) || $this->hasMutator($fieldName)) {
$componentName = $this->_table->getComponentName();
$mutator = $this->hasMutator($fieldName)
? $this->getMutator($fieldName):
'set' . Doctrine_Inflector::classify($fieldName);
if ($this->hasMutator($fieldName) || method_exists($this, $mutator)) {
$this->hasMutator($fieldName, $mutator);
return $this->$mutator($value, $load, $fieldName);
}
}
return $this->_set($fieldName, $value, $load);
}
Doctrine_Access::setArray ( array  $array)
inherited

Set an entire aray to the data

Parameters
array$arrayAn array of key => value pairs
Returns
Doctrine_Access

Definition at line 41 of file Access.php.

{
foreach ($array as $k => $v) {
$this->set($k, $v);
}
return $this;
}
Doctrine_Record_Abstract::setColumnOption (   $columnName,
  $option,
  $value 
)
inherited

Set an individual column option

Parameters
string$columnName
string$option
string$value
Returns
void

Definition at line 310 of file Abstract.php.

{
$this->_table->setColumnOption($columnName, $option, $value);
}
Doctrine_Record_Abstract::setColumnOptions (   $name,
array  $options 
)
inherited

Customize the array of options for a column or multiple columns. First argument can be a single field/column name or an array of them. The second argument is an array of options.

[php]
public function setTableDefinition()
{
    parent::setTableDefinition();
    $this->setColumnOptions('username', array(
        'unique' => true
    ));
}
Parameters
string$columnName
array$validators
Returns
void

Definition at line 297 of file Abstract.php.

{
$this->_table->setColumnOptions($name, $options);
}
Doctrine_Record_Abstract::setListener (   $listener)
inherited

setListener

Parameters
Doctrine_EventListener_Interface | Doctrine_Overloadable$listener
Returns
Doctrine_Record

Definition at line 90 of file Abstract.php.

{
$this->_table->setRecordListener($listener);
return $this;
}
Doctrine_Locator_Injectable::setLocator ( Doctrine_Locator  $locator)
inherited

setLocator this method can be used for setting the locator object locally

Parameters
Doctrine_Locatorthe locator object
Returns
Doctrine_Locator_Injectable this instance

Definition at line 60 of file Injectable.php.

{
$this->_locator = $locator;
return $this;
}
Doctrine_Record::setRelated (   $alias,
Doctrine_Access  $coll 
)
final

set a related component

Parameters
string$alias
Doctrine_Access$coll

Definition at line 2349 of file Record.php.

{
$this->_references[$alias] = $coll;
}
Doctrine_Record::setUp ( )

setUp this method is used for setting up relations and attributes it should be implemented by child classes

Returns
void

Definition at line 304 of file Record.php.

{ }
Doctrine_Record::state (   $state = null)

assigns the state of this record or returns it if called without parameters

Parameters
integer | string$stateif set, this method tries to set the record state to $state
See Also
Doctrine_Record::STATE_* constants
Exceptions
Doctrine_Record_State_Exceptionif trying to set an unknown state
Returns
null|integer

Definition at line 922 of file Record.php.

{
if ($state == null) {
return $this->_state;
}
$err = false;
if (is_integer($state)) {
if ($state >= 1 && $state <= 7) {
$this->_state = $state;
} else {
$err = true;
}
} else if (is_string($state)) {
$upper = strtoupper($state);
$const = 'Doctrine_Record::STATE_' . $upper;
if (defined($const)) {
$this->_state = constant($const);
} else {
$err = true;
}
}
if ($this->_state === Doctrine_Record::STATE_TCLEAN ||
$this->_state === Doctrine_Record::STATE_CLEAN) {
$this->_resetModified();
}
if ($err) {
throw new Doctrine_Record_State_Exception('Unknown record state ' . $state);
}
}
Doctrine_Record::synchronizeWithArray ( array  $array,
  $deep = true 
)

synchronizes a Doctrine_Record instance and its relations with data from an array

it expects an array representation of a Doctrine_Record similar to the return value of the toArray() method. If the array contains relations it will create those that don't exist, update the ones that do, and delete the ones missing on the array but available on the Doctrine_Record (unlike

See Also
fromArray() that does not touch what it is not in $array)
Parameters
array$arrayrepresentation of a Doctrine_Record
bool$deepwhether or not to act on relations

Definition at line 2023 of file Record.php.

{
$refresh = false;
foreach ($array as $key => $value) {
if ($key == '_identifier') {
$refresh = true;
$this->assignIdentifier($value);
continue;
}
if ($deep && $this->getTable()->hasRelation($key)) {
if ( ! $this->$key) {
$this->refreshRelated($key);
}
if (is_array($value)) {
if (isset($value[0]) && ! is_array($value[0])) {
$this->unlink($key, array(), false);
$this->link($key, $value, false);
} else {
$this->$key->synchronizeWithArray($value);
$this->$key = $this->$key;
}
}
} else if ($this->getTable()->hasField($key) || array_key_exists($key, $this->_values)) {
$this->set($key, $value);
}
}
// Eliminate relationships missing in the $array
foreach ($this->_references as $name => $relation) {
$rel = $this->getTable()->getRelation($name);
if ( ! $rel->isRefClass() && ! isset($array[$name]) && ( ! $rel->isOneToOne() || ! isset($array[$rel->getLocalFieldName()]))) {
unset($this->$name);
}
}
if ($refresh) {
$this->refresh();
}
}
Doctrine_Record::toArray (   $deep = true,
  $prefixKey = false 
)

returns the record representation as an array

boolean $deep whether to include relations boolean $prefixKey not used array

Definition at line 1892 of file Record.php.

{
if ($this->_state == self::STATE_LOCKED || $this->_state == self::STATE_TLOCKED) {
return false;
}
$stateBeforeLock = $this->_state;
$this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED;
$a = array();
foreach ($this as $column => $value) {
if ($value === self::$_null || is_object($value)) {
$value = null;
}
$columnValue = $this->get($column, false);
if ($columnValue instanceof Doctrine_Record) {
$a[$column] = $columnValue->getIncremented();
} else {
$a[$column] = $columnValue;
}
}
if ($this->_table->getIdentifierType() == Doctrine_Core::IDENTIFIER_AUTOINC) {
$i = $this->_table->getIdentifier();
$a[$i] = $this->getIncremented();
}
if ($deep) {
foreach ($this->_references as $key => $relation) {
if ( ! $relation instanceof Doctrine_Null) {
$a[$key] = $relation->toArray($deep, $prefixKey);
}
}
}
// [FIX] Prevent mapped Doctrine_Records from being displayed fully
foreach ($this->_values as $key => $value) {
$a[$key] = ($value instanceof Doctrine_Record || $value instanceof Doctrine_Collection)
? $value->toArray($deep, $prefixKey) : $value;
}
$this->_state = $stateBeforeLock;
return $a;
}
Doctrine_Record::toString ( )

__toString alias

Returns
string

Definition at line 2705 of file Record.php.

{
return Doctrine_Core::dump(get_object_vars($this));
}
Doctrine_Record::trySave ( Doctrine_Connection  $conn = null)

tries to save the object and all its related components. In contrast to Doctrine_Record::save(), this method does not throw an exception when validation fails but returns TRUE on success or FALSE on failure.

Parameters
Doctrine_Connection$connoptional connection parameter
Returns
TRUE if the record was saved sucessfully without errors, FALSE otherwise.

Definition at line 1730 of file Record.php.

{
try {
$this->save($conn);
return true;
} catch (Doctrine_Validator_Exception $ignored) {
return false;
}
}
Doctrine_Record_Abstract::unique (   $fields,
  $options = array(),
  $createUniqueIndex = true 
)
inherited

Defines a n-uple of fields that must be unique for every record.

This method Will automatically add UNIQUE index definition and validate the values on save. The UNIQUE index is not created in the database until you use

See Also
export().
Parameters
array$fieldsvalues are fieldnames
array$optionsarray of options for unique validator
bool$createUniqueIndexWhether or not to create a unique index in the database
Returns
void

Definition at line 128 of file Abstract.php.

{
return $this->_table->unique($fields, $options, $createUniqueIndex);
}
Doctrine_Record::unlink (   $alias,
  $ids = array(),
  $now = false 
)

unlink removes links from this record to given records if no ids are given, it removes all links

Parameters
string$aliasrelated component alias
array$idsthe identifiers of the related records
boolean$nowwhether or not to execute now or set as pending unlinks
Returns
Doctrine_Record this object (fluent interface)

Definition at line 2428 of file Record.php.

{
$ids = (array) $ids;
// fix for #1622
if ( ! isset($this->_references[$alias]) && $this->hasRelation($alias)) {
$this->loadReference($alias);
}
$allIds = array();
if (isset($this->_references[$alias])) {
if ($this->_references[$alias] instanceof Doctrine_Record) {
$allIds[] = $this->_references[$alias]->identifier();
if (in_array($this->_references[$alias]->identifier(), $ids) || empty($ids)) {
unset($this->_references[$alias]);
}
} else {
$allIds = $this->get($alias)->getPrimaryKeys();
foreach ($this->_references[$alias] as $k => $record) {
if (in_array(current($record->identifier()), $ids) || empty($ids)) {
$this->_references[$alias]->remove($k);
}
}
}
}
if ( ! $this->exists() || $now === false) {
if ( ! $ids) {
$ids = $allIds;
}
foreach ($ids as $id) {
$this->_pendingUnlinks[$alias][$id] = true;
}
return $this;
} else {
return $this->unlinkInDb($alias, $ids);
}
}
Doctrine_Record::unlinkInDb (   $alias,
  $ids = array() 
)

unlink now the related components, querying the db

Parameters
string$aliasrelated component alias
array$idsthe identifiers of the related records
Returns
Doctrine_Record this object (fluent interface)

Definition at line 2473 of file Record.php.

{
$rel = $this->getTable()->getRelation($alias);
if ($rel instanceof Doctrine_Relation_Association) {
$q = $rel->getAssociationTable()
->createQuery()
->delete()
->where($rel->getLocal() . ' = ?', array_values($this->identifier()));
if (count($ids) > 0) {
$q->whereIn($rel->getForeign(), $ids);
}
$q->execute();
} else if ($rel instanceof Doctrine_Relation_ForeignKey) {
$q = $rel->getTable()->createQuery()
->update()
->set($rel->getForeign(), '?', array(null))
->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier()));
if (count($ids) > 0) {
$q->whereIn($rel->getTable()->getIdentifier(), $ids);
}
$q->execute();
}
return $this;
}
Doctrine_Record::unserialize (   $serialized)

this method is automatically called everytime an instance is unserialized

Parameters
string$serializedDoctrine_Record as serialized string
Exceptions
Doctrine_Record_Exceptionif the cleanData operation fails somehow
Returns
void

Definition at line 857 of file Record.php.

{
$event = new Doctrine_Event($this, Doctrine_Event::RECORD_UNSERIALIZE);
$connection = $manager->getConnectionForComponent(get_class($this));
$this->_table = $connection->getTable(get_class($this));
$this->preUnserialize($event);
$this->getTable()->getRecordListener()->preUnserialize($event);
$array = unserialize($serialized);
foreach($array as $k => $v) {
$this->$k = $v;
}
foreach ($this->_data as $k => $v) {
switch ($this->_table->getTypeOf($k)) {
case 'array':
case 'object':
$this->_data[$k] = unserialize($this->_data[$k]);
break;
case 'gzip':
$this->_data[$k] = gzuncompress($this->_data[$k]);
break;
case 'enum':
$this->_data[$k] = $this->_table->enumValue($k, $this->_data[$k]);
break;
}
}
// Remove existing record from the repository and table entity map.
$this->_table->setData($this->_data);
$existing_record = $this->_table->getRecord();
if ($existing_record->exists()) {
$this->_table->getRepository()->evict($existing_record->getOid());
$this->_table->removeRecord($existing_record);
}
// Add the unserialized record to repository and entity map.
$this->_oid = self::$_index;
self::$_index++;
$this->_table->getRepository()->add($this);
$this->_table->addRecord($this);
$this->cleanData($this->_data);
$this->prepareIdentifiers($this->exists());
$this->postUnserialize($event);
$this->getTable()->getRecordListener()->postUnserialize($event);
}
Doctrine_Record::validate ( )
protected

Empty template method to provide concrete Record classes with the possibility to hook into the validation procedure, doing any custom / specialized validations that are neccessary.

Definition at line 447 of file Record.php.

{ }
Doctrine_Record::validateOnInsert ( )
protected

Empty template method to provide concrete Record classes with the possibility to hook into the validation procedure only when the record is going to be inserted into the data store the first time.

Definition at line 463 of file Record.php.

{ }
Doctrine_Record::validateOnUpdate ( )
protected

Empty template method to provide concrete Record classes with the possibility to hook into the validation procedure only when the record is going to be updated.

Definition at line 455 of file Record.php.

{ }

Field Documentation

array Doctrine_Record::$_pendingUnlinks = array()
protected

Array of pending un links in format alias => keys to be executed after save

Definition at line 160 of file Record.php.

Doctrine_Record_Abstract::$_table
protectedinherited
Parameters
Doctrine_Table$_tablereference to associated Doctrine_Table instance

Definition at line 38 of file Abstract.php.

const Doctrine_Record::STATE_CLEAN = 3

CLEAN STATE a Doctrine_Record is in clean state when all of its properties are loaded from the database and none of its properties are changed

Definition at line 58 of file Record.php.

const Doctrine_Record::STATE_DIRTY = 1

STATE CONSTANTS DIRTY STATE a Doctrine_Record is in dirty state when its properties are changed

Definition at line 44 of file Record.php.

const Doctrine_Record::STATE_LOCKED = 6

LOCKED STATE a Doctrine_Record is temporarily locked during deletes and saves

This state is used internally to ensure that circular deletes and saves will not cause infinite loops

Definition at line 79 of file Record.php.

const Doctrine_Record::STATE_PROXY = 4

PROXY STATE a Doctrine_Record is in proxy state when its properties are not fully loaded

Definition at line 64 of file Record.php.

const Doctrine_Record::STATE_TCLEAN = 5

NEW TCLEAN a Doctrine_Record is in transient clean state when it is created and none of its fields are modified

Definition at line 70 of file Record.php.

const Doctrine_Record::STATE_TDIRTY = 2

TDIRTY STATE a Doctrine_Record is in transient dirty state when it is created and some of its fields are modified but it is NOT yet persisted into database

Definition at line 51 of file Record.php.

const Doctrine_Record::STATE_TLOCKED = 7

TLOCKED STATE a Doctrine_Record is temporarily locked (and transient) during deletes and saves

This state is used internally to ensure that circular deletes and saves will not cause infinite loops

Definition at line 88 of file Record.php.


The documentation for this class was generated from the following file: