class Doctrine_Table extends Doctrine_Configurable implements Countable (View source)

Doctrine_Table represents a database table each Doctrine_Table holds the information of foreignKeys and associations

Properties

protected Doctrine_Locator $_locator from Doctrine_Locator_Injectable
protected array $_resources from Doctrine_Locator_Injectable
static protected Doctrine_Null $_null from Doctrine_Locator_Injectable
protected array $attributes from Doctrine_Configurable
protected Doctrine_Configurable $parent from Doctrine_Configurable
protected array $_impl from Doctrine_Configurable
protected array $_params from Doctrine_Configurable
protected array $_data
protected mixed $_identifier
protected integer $_identifierType
protected Doctrine_Connection $_conn
protected array $_identityMap
protected Doctrine_Table_Repository $_repository
protected array $_columns
protected array $_uniques Array of unique sets of fields. These values are validated on save
protected array $_fieldNames
protected array $_columnNames
protected integer $columnCount
protected boolean $hasDefaultValues
protected array $_options
protected Doctrine_Tree $_tree
protected Doctrine_Relation_Parser $_parser
protected array $_templates
protected array $_filters
protected array $_generators
protected Doctrine_Record_Generator $_generator Generator instance responsible for constructing this table
protected array $_invokedMethods
protected Doctrine_Record $record

Methods

setLocator(Doctrine_Locator $locator)

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

getLocator()

getLocator returns the locator associated with this object

mixed
locate(string $name)

locate locates a resource by given name and returns it

bind(array $args, integer $type)

Adds a relation to the table.

static void
initNullObject(Doctrine_Null $null)

initNullObject initializes the null object

static Doctrine_Null
getNullObject()

getNullObject returns the null object associated with this object

void
setAttribute(mixed $attribute, mixed $value)

setAttribute sets a given attribute

getParams($namespace = null)

No description

getParamNamespaces()

No description

setParam($name, $value, $namespace = null)

No description

getParam($name, $namespace = null)

No description

setImpl(string $template, string $class)

setImpl binds given class to given template name

string
getImpl($template)

getImpl returns the implementation for given class

hasImpl($template)

No description

void
setEventListener(Doctrine_EventListener $listener)

No description

addRecordListener($listener, $name = null)

addRecordListener

addListener($listener, $name = null)

addListener

mixed
getAttribute(integer $attribute)

returns the value of an attribute

void
unsetAttribute(integer $attribute)

Unset an attribute from this levels attributes

array
getAttributes()

getAttributes returns all attributes as an array

setCharset(string $charset)

Set the charset

mixed
getCharset()

Get the charset

setCollate(string $collate)

Set the collate

mixed
getCollate()

Get the collate

void
setParent(Doctrine_Configurable $component)

sets a parent for this configurable component the parent must be configurable component itself

getParent()

getParent returns the parent of this component

__construct(string $name, Doctrine_Connection $conn, boolean $initDefinition = false)

the constructor

void
construct()

Construct template method.

initDefinition()

Initializes the in-memory table definition.

void
initIdentifier()

Initializes the primary key.

string
getColumnOwner(string $columnName)

Gets the owner of a column.

getRecordInstance()

Gets the record instance for this table.

boolean
isInheritedColumn($columnName)

Checks whether a column is inherited from a component further up in the hierarchy.

boolean
isIdentifier(string $fieldName)

Checks whether a field is in the primary key.

boolean
isIdentifierAutoincrement()

Checks whether a field identifier is of type autoincrement.

boolean
isIdentifierComposite()

Checks whether a field identifier is a composite key.

void
getMethodOwner(string $method)

getMethodOwner

setMethodOwner(string $method, string $class)

setMethodOwner

boolean
export()

Exports this table to database based on the schema definition.

array
getExportableFormat(boolean $parseForeignKeys = true)

Returns an exportable representation of this object.

boolean
_checkForeignKeyExists(array $def, array $foreignKeys)

Check if a foreign definition already exists in the fks array for a foreign table, local and foreign key

getRelationParser()

Retrieves the relation parser associated with this table.

mixed
__get(string $option)

Magic method for accessing to object properties.

__isset(string $option)

Magic method for testing object properties existence.

array
getOptions()

Retrieves all options of this table and the associated values.

void
setOptions(array $options)

Sets all the options.

void
addForeignKey(array $definition)

Adds a foreignKey to the table in-memory definition.

void
addCheckConstraint($definition, mixed $name)

Adds a check constraint to the table in-memory definition.

void
addIndex(string $index, array $definition)

Adds an index to this table in-memory definition.

array|boolean
getIndex(string $index)

Retrieves an index definition.

void
unique($fields, $options = array(), $createdUniqueIndex = true)

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

hasOne()

Binds One-to-One aggregate relation

hasMany()

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

boolean
hasRelation(string $alias)

Tests if a relation exists.

getRelation($alias, $recursive = true)

Retrieves a relation object for this component.

array
getRelations()

Retrieves all relation objects defined on this table.

createQuery(string $alias = '')

Creates a query on this table.

getRepository()

Gets the internal record repository.

setOption(string $name, mixed $value)

Sets an option for the table.

mixed
getOption(string $name)

Returns the value of a given option.

string
getOrderByStatement(string $alias = null, boolean $columnNames = false)

Get the table orderby statement

string
processOrderBy(string $alias, string $orderBy, string $columnNames = false)

Process an order by statement to be prefixed with the passed alias and field names converted to column names if the 3rd argument is true.

string
getColumnName($fieldName)

Returns a column name for a column alias.

array
getColumnDefinition(string $columnName)

Retrieves a column definition from this table schema.

string
getFieldName(string $columnName)

Returns a column alias for a column name.

void
setColumnOptions($columnName, array $options)

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.

void
setColumnOption(string $columnName, string $option, string $value)

Set an individual column option

void
setColumns(array $definitions)

Set multiple column definitions at once

void
setColumn(string $name, string $type = null, integer $length = null, mixed $options = array(), boolean $prepend = false)

Adds a column to the schema.

boolean
hasDefaultValues()

Finds out whether this table has default values for columns.

mixed
getDefaultValueOf(string $fieldName)

Retrieves the default value (if any) for a given column.

string
getIdentifier()

Returns the definition of the identifier key.

integer
getIdentifierType()

Retrieves the type of primary key.

boolean
hasColumn(string $columnName)

Finds out whether the table definition contains a given column.

boolean
hasField(string $fieldName)

Finds out whether the table definition has a given field.

setConnection(Doctrine_Connection $conn)

Sets the default connection for this table.

getConnection()

Returns the connection associated with this table (if any).

create(array $array = array())

Creates a new record.

void
addNamedQuery($queryKey, string|Doctrine_Query $query)

Adds a named query in the query registry.

createNamedQuery(string $queryKey)

Creates a named query from one in the query registry.

mixed
find()

Finds a record by its identifier.

findAll(int $hydrationMode = null)

Retrieves all the records stored in this table.

findBySql(string $dql, array $params = array(), int $hydrationMode = null)

Finds records in this table with a given SQL where clause.

findByDql(string $dql, array $params = array(), int $hydrationMode = null)

Finds records in this table with a given DQL where clause.

findBy($fieldName, $value, $hydrationMode = null)

Find records basing on a field.

findOneBy($fieldName, $value, $hydrationMode = null)

Finds the first record that satisfy the clause.

execute(string $queryKey, array $params = array(), int $hydrationMode = Doctrine_Core::HYDRATE_RECORD)

Finds result of a named query.

executeOne(string $queryKey, array $params = array(), int $hydrationMode = Doctrine_Core::HYDRATE_RECORD)

Fetches one record with a named query.

void
clear()

Clears the first level cache (identityMap).

boolean
addRecord(Doctrine_Record $record)

Adds a record to the first level cache (identity map).

boolean
removeRecord(Doctrine_Record $record)

Removes a record from the identity map.

getRecord()

Returns a new record.

string
getClassnameToReturn() deprecated

Get the classname to return. Most often this is just the options['name'].

getProxy($id = null)

No description

string
applyInheritance($where)

applyInheritance

integer
count()

Implements Countable interface.

getQueryObject()

No description

array
getEnumValues(string $fieldName)

Retrieves the enum values for a given field.

mixed
enumValue(string $fieldName, integer $index)

Retrieves an enum value.

integer
enumIndex(string $fieldName, mixed $value)

Retrieves an enum index.

validateField(string $fieldName, string $value, Doctrine_Record $record = null)

Validates a given field using table ATTR_VALIDATE rules.

validateUniques(Doctrine_Record $record)

Validates all the unique indexes.

integer
getColumnCount()

No description

array
getColumns()

Retrieves all columns of the table.

boolean
removeColumn(string $fieldName)

Removes a field name from the table schema information.

array
getColumnNames(array $fieldNames = null)

Returns an array containing all the column names.

array
getIdentifierColumnNames()

Returns an array with all the identifier column names.

array
getUniques()

Gets the array of unique fields sets.

array
getFieldNames()

Returns an array containing all the field names.

array
getDefinitionOf(string $fieldName)

Retrieves the definition of a field.

string
getTypeOf(string $fieldName)

Retrieves the type of a field.

string
getTypeOfColumn(string $columnName)

Retrieves the type of a column.

void
setData(array $data)

Doctrine uses this function internally.

array
getData()

Returns internal data.

mixed
prepareValue($fieldName, $value, $typeHint = null)

Performs special data preparation.

getTree()

Gets associated tree.

string
getComponentName()

Gets the subclass of Doctrine_Record that belongs to this table.

string
getTableName()

Gets the table name in the db.

void
setTableName(string $tableName)

sets the table name in the schema definition.

boolean
isTree()

Determines if table acts as tree.

array
getTemplates()

Retrieves all templates (behaviors) attached to this table.

getTemplate(string $template)

Retrieves a particular template by class name.

boolean
hasTemplate(string $template)

Checks if the table has a given template.

addTemplate(string $template, Doctrine_Template $impl)

Adds a template to this table.

array
getGenerators()

Gets all the generators for this table.

getGenerator(string $generator)

Gets generator instance for a passed name.

void
hasGenerator(string $generator)

Checks if a generator name exists.

addGenerator(Doctrine_Record_Generator $generator, string $name = null)

Adds a generate to the table instance.

void
setGenerator(Doctrine_Record_Generator $generator)

Set the generator responsible for creating this table

boolean
isGenerator()

Check whether this table was created by a record generator or not

getParentGenerator()

Get the parent generator responsible for this table instance

bindQueryParts(array $queryParts)

Binds query parts to this component.

bindQueryPart(string $queryPart, mixed $value)

Adds default query parts to the selects executed on this table.

array
getFieldValidators(string $fieldName)

Gets the names of all validators being applied on a field.

integer
getFieldLength(string $fieldName)

Gets the maximum length of a field.

string
getBoundQueryPart(string $queryPart)

Retrieves a bound query part.

array
getFilters()

getFilters

string
__toString()

Generates a string representation of this object.

buildFindByWhere($fieldName)

No description

string
_resolveFindByFieldName(string $name)

Resolves the passed find by field name inflecting the parameter.

the
__call($method, $arguments)

Adds support for magic finders.

Details

Doctrine_Locator_Injectable setLocator(Doctrine_Locator $locator)

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

Parameters

Doctrine_Locator $locator the locator object

Return Value

Doctrine_Locator_Injectable this instance

Doctrine_Locator getLocator()

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

Return Value

Doctrine_Locator

mixed locate(string $name)

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

Parameters

string $name the name of the resource

Return Value

mixed the located resource

Exceptions

Doctrine_Locator_Exception if the resource could not be found

See also

Doctrine_Locator::locate

Doctrine_Locator bind(array $args, integer $type)

Adds a relation to the table.

This method defines a relation on this table, that will be present on every record belonging to this component.

Parameters

array $args first value is a string, name of related component; second value is array, options for the relation. see Doctrine_Relation::_$definition
integer $type Doctrine_Relation::ONE or Doctrine_Relation::MANY

Return Value

Doctrine_Locator this object

static void initNullObject(Doctrine_Null $null)

initNullObject initializes the null object

Parameters

Doctrine_Null $null

Return Value

void

static Doctrine_Null getNullObject()

getNullObject returns the null object associated with this object

Return Value

Doctrine_Null

void setAttribute(mixed $attribute, mixed $value)

setAttribute sets a given attribute

$manager->setAttribute(Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_ALL);

Parameters

mixed $attribute either a Doctrine_Core::ATTR_* integer constant or a string corresponding to a constant
mixed $value the value of the attribute

Return Value

void

Exceptions

Doctrine_Exception if the value is invalid

See also

Doctrine_Core::ATTR_* constants

getParams($namespace = null)

Parameters

$namespace

getParamNamespaces()

setParam($name, $value, $namespace = null)

Parameters

$name
$value
$namespace

getParam($name, $namespace = null)

Parameters

$name
$namespace

Doctrine_Configurable setImpl(string $template, string $class)

setImpl binds given class to given template name

this method is the base of Doctrine dependency injection

Parameters

string $template name of the class template
string $class name of the class to be bound

Return Value

Doctrine_Configurable this object

string getImpl($template)

getImpl returns the implementation for given class

Parameters

$template

Return Value

string name of the concrete implementation

hasImpl($template)

Parameters

$template

void setEventListener(Doctrine_EventListener $listener)

Parameters

Doctrine_EventListener $listener

Return Value

void

Doctrine_Configurable addRecordListener($listener, $name = null)

addRecordListener

Parameters

$listener
$name

Return Value

Doctrine_Configurable this object

Doctrine_Configurable addListener($listener, $name = null)

addListener

Parameters

$listener
$name

Return Value

Doctrine_Configurable this object

mixed getAttribute(integer $attribute)

returns the value of an attribute

Parameters

integer $attribute

Return Value

mixed

void unsetAttribute(integer $attribute)

Unset an attribute from this levels attributes

Parameters

integer $attribute

Return Value

void

array getAttributes()

getAttributes returns all attributes as an array

Return Value

array

setCharset(string $charset)

Set the charset

Parameters

string $charset

mixed getCharset()

Get the charset

Return Value

mixed

setCollate(string $collate)

Set the collate

Parameters

string $collate

mixed getCollate()

Get the collate

Return Value

mixed $collate

void setParent(Doctrine_Configurable $component)

sets a parent for this configurable component the parent must be configurable component itself

Parameters

Doctrine_Configurable $component

Return Value

void

Doctrine_Configurable getParent()

getParent returns the parent of this component

Return Value

Doctrine_Configurable

__construct(string $name, Doctrine_Connection $conn, boolean $initDefinition = false)

the constructor

Parameters

string $name the name of the component
Doctrine_Connection $conn the connection associated with this table
boolean $initDefinition whether to init the in-memory schema

Exceptions

Doctrine_Connection_Exception if there are no opened connections

void construct()

Construct template method.

This method provides concrete Table classes with the possibility to hook into the constructor procedure. It is called after the Doctrine_Table construction process is finished.

Return Value

void

initDefinition()

Initializes the in-memory table definition.

void initIdentifier()

Initializes the primary key.

Called in the construction process, builds the identifier definition copying in the schema the list of the fields which constitutes the primary key.

Return Value

void

string getColumnOwner(string $columnName)

Gets the owner of a column.

The owner of a column is the name of the component in a hierarchy that defines the column.

Parameters

string $columnName the column name

Return Value

string the name of the owning/defining component

Doctrine_Record getRecordInstance()

Gets the record instance for this table.

The Doctrine_Table instance always holds at least one instance of a model so that it can be reused for several things, but primarily it is first used to instantiate all the internal in memory schema definition.

Return Value

Doctrine_Record Empty instance of the record

boolean isInheritedColumn($columnName)

Checks whether a column is inherited from a component further up in the hierarchy.

Parameters

$columnName The column name

Return Value

boolean TRUE if column is inherited, FALSE otherwise.

boolean isIdentifier(string $fieldName)

Checks whether a field is in the primary key.

Checks if $fieldName is part of the table identifier, which defines the one-column or multi-column primary key.

Parameters

string $fieldName The field name

Return Value

boolean TRUE if the field is part of the table identifier/primary key field(s),

boolean isIdentifierAutoincrement()

Checks whether a field identifier is of type autoincrement.

This method checks if the primary key is a AUTOINCREMENT column or if the table uses a natural key.

Return Value

boolean TRUE if the identifier is autoincrement FALSE otherwise

boolean isIdentifierComposite()

Checks whether a field identifier is a composite key.

Return Value

boolean TRUE if the identifier is a composite key, FALSE otherwise

void getMethodOwner(string $method)

getMethodOwner

Parameters

string $method

Return Value

void

setMethodOwner(string $method, string $class)

setMethodOwner

Parameters

string $method
string $class

boolean export()

Exports this table to database based on the schema definition.

This method create a physical table in the database, using the definition that comes from the component Doctrine_Record instance.

Return Value

boolean whether or not the export operation was successful false if table already existed in the database

Exceptions

Doctrine_Connection_Exception if some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation

array getExportableFormat(boolean $parseForeignKeys = true)

Returns an exportable representation of this object.

This method produces a array representation of the table schema, where keys are tableName, columns (see $_columns) and options. The options subarray contains 'primary' and 'foreignKeys'.

Parameters

boolean $parseForeignKeys whether to include foreign keys definition in the options

Return Value

array

protected boolean _checkForeignKeyExists(array $def, array $foreignKeys)

Check if a foreign definition already exists in the fks array for a foreign table, local and foreign key

Parameters

array $def Foreign key definition to check for
array $foreignKeys Array of existing foreign key definitions to check in

Return Value

boolean $result Whether or not the foreign key was found

Doctrine_Relation_Parser getRelationParser()

Retrieves the relation parser associated with this table.

Return Value

Doctrine_Relation_Parser relation parser object

mixed __get(string $option)

Magic method for accessing to object properties.

This method is an alias for getOption. foreach ($table->indexes as $name => $definition) { // ... }

Parameters

string $option

Return Value

mixed

__isset(string $option)

Magic method for testing object properties existence.

This method tests if an option exists. if (isset($table->tableName)) { // ... }

Parameters

string $option

array getOptions()

Retrieves all options of this table and the associated values.

Return Value

array all options and their values

void setOptions(array $options)

Sets all the options.

This method sets options of the table that are specified in the argument. It has no effect on other options.

Parameters

array $options keys are option names

Return Value

void

void addForeignKey(array $definition)

Adds a foreignKey to the table in-memory definition.

This method adds a foreign key to the schema definition. It does not add the key to the physical table in the db; see export().

Parameters

array $definition definition of the foreign key

Return Value

void

void addCheckConstraint($definition, mixed $name)

Adds a check constraint to the table in-memory definition.

This method adds a CHECK constraint to the schema definition. It does not add the constraint to the physical table in the db; see export().

Parameters

$definition
mixed $name if string used as name for the constraint. Otherwise it is indexed numerically.

Return Value

void

void addIndex(string $index, array $definition)

Adds an index to this table in-memory definition.

This method adds an INDEX to the schema definition. It does not add the index to the physical table in the db; see export().

Parameters

string $index index name
array $definition keys are type, fields

Return Value

void

array|boolean getIndex(string $index)

Retrieves an index definition.

This method returns a given index definition: see addIndex().

Parameters

string $index index name; see addIndex()

Return Value

array|boolean array on success, FALSE on failure

void unique($fields, $options = array(), $createdUniqueIndex = true)

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 export().

Parameters

$fields
$options
$createdUniqueIndex

Return Value

void

Doctrine_Record hasOne()

Binds One-to-One aggregate relation

Return Value

Doctrine_Record this object

See also

Doctrine_Relation::_$definition

Doctrine_Record hasMany()

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

Return Value

Doctrine_Record this object

See also

Doctrine_Relation::_$definition

boolean hasRelation(string $alias)

Tests if a relation exists.

This method queries the table definition to find out if a relation is defined for this component. Alias defined with foreignAlias are not recognized as there's only one Doctrine_Relation object on the owning side.

Parameters

string $alias the relation alias to search for.

Return Value

boolean true if the relation exists. Otherwise false.

Doctrine_Relation getRelation($alias, $recursive = true)

Retrieves a relation object for this component.

Parameters

$alias
$recursive

Return Value

Doctrine_Relation

array getRelations()

Retrieves all relation objects defined on this table.

Return Value

array

Doctrine_Query createQuery(string $alias = '')

Creates a query on this table.

This method returns a new Doctrine_Query object and adds the component name of this table as the query 'from' part. $table = Doctrine_Core::getTable('User'); $table->createQuery('myuser') ->where('myuser.Phonenumber = ?', '5551234');

Parameters

string $alias name for component aliasing

Return Value

Doctrine_Query

Doctrine_Table_Repository getRepository()

Gets the internal record repository.

Doctrine_Table setOption(string $name, mixed $value)

Sets an option for the table.

This method sets an option and returns this object in order to allow flexible method chaining.

Parameters

string $name the name of the option to set
mixed $value the value of the option

Return Value

Doctrine_Table this object

See also

Doctrine_Table::$_options for available options

mixed getOption(string $name)

Returns the value of a given option.

Parameters

string $name the name of the option

Return Value

mixed the value of given option

See also

Doctrine_Table::$_options for available options

string getOrderByStatement(string $alias = null, boolean $columnNames = false)

Get the table orderby statement

Parameters

string $alias The alias to use
boolean $columnNames Whether or not to use column names instead of field names

Return Value

string $orderByStatement

string processOrderBy(string $alias, string $orderBy, string $columnNames = false)

Process an order by statement to be prefixed with the passed alias and field names converted to column names if the 3rd argument is true.

Parameters

string $alias The alias to prefix columns with
string $orderBy The order by to process
string $columnNames Whether or not to convert field names to column names

Return Value

string $orderBy

string getColumnName($fieldName)

Returns a column name for a column alias.

If the actual name for the alias cannot be found this method returns the given alias.

Parameters

$fieldName

Return Value

string column name

array getColumnDefinition(string $columnName)

Retrieves a column definition from this table schema.

Parameters

string $columnName

Return Value

array column definition; see $_columns

string getFieldName(string $columnName)

Returns a column alias for a column name.

If no alias can be found the column name is returned.

Parameters

string $columnName column name

Return Value

string column alias

void setColumnOptions($columnName, array $options)

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

$columnName
array $options

Return Value

void

void setColumnOption(string $columnName, string $option, string $value)

Set an individual column option

Parameters

string $columnName
string $option
string $value

Return Value

void

void setColumns(array $definitions)

Set multiple column definitions at once

Parameters

array $definitions

Return Value

void

void setColumn(string $name, string $type = null, integer $length = null, mixed $options = array(), boolean $prepend = false)

Adds a column to the schema.

This method does not alter the database table; see export();

Parameters

string $name column physical name
string $type type of data
integer $length maximum length
mixed $options
boolean $prepend Whether to prepend or append the new column to the column list. By default the column gets appended.

Return Value

void

Exceptions

Doctrine_Table_Exception if trying use wrongly typed parameter

See also

$_columns;

boolean hasDefaultValues()

Finds out whether this table has default values for columns.

Return Value

boolean

mixed getDefaultValueOf(string $fieldName)

Retrieves the default value (if any) for a given column.

Parameters

string $fieldName column name

Return Value

mixed default value as set in definition

string getIdentifier()

Returns the definition of the identifier key.

Return Value

string can be array if a multi-column primary key is used.

integer getIdentifierType()

Retrieves the type of primary key.

This method finds out if the primary key is multifield.

Return Value

integer

See also

Doctrine_Identifier constants

boolean hasColumn(string $columnName)

Finds out whether the table definition contains a given column.

Parameters

string $columnName

Return Value

boolean

boolean hasField(string $fieldName)

Finds out whether the table definition has a given field.

This method returns true if see hasColumn() returns true or if an alias named $fieldName exists.

Parameters

string $fieldName

Return Value

boolean

Doctrine_Table setConnection(Doctrine_Connection $conn)

Sets the default connection for this table.

This method assign the connection which this table will use to create queries.

Parameters

Doctrine_Connection $conn

Return Value

Doctrine_Table this object; fluent interface

Doctrine_Connection|null getConnection()

Returns the connection associated with this table (if any).

Return Value

Doctrine_Connection|null the connection object

Doctrine_Record create(array $array = array())

Creates a new record.

This method create a new instance of the model defined by this table. The class of this record is the subclass of Doctrine_Record defined by this component. The record is not created in the database until you call @save().

Parameters

array $array an array where keys are field names and values representing field values. Can contain also related components; see Doctrine_Record::fromArray()

Return Value

Doctrine_Record the created record object

void addNamedQuery($queryKey, string|Doctrine_Query $query)

Adds a named query in the query registry.

This methods register a query object with a name to use in the future.

Parameters

$queryKey query key name to use for storage
string|Doctrine_Query $query DQL string or object

Return Value

void

See also

createNamedQuery()

Doctrine_Query createNamedQuery(string $queryKey)

Creates a named query from one in the query registry.

This method clones a new query object from a previously registered one.

Parameters

string $queryKey query key name

Return Value

Doctrine_Query

See also

addNamedQuery()

mixed find()

Finds a record by its identifier.

$table->find(11); $table->find(11, Doctrine_Core::HYDRATE_RECORD); $table->find('namedQueryForYearArchive', array(2009), Doctrine_Core::HYDRATE_ARRAY);

Return Value

mixed Doctrine_Collection, array, Doctrine_Record or false if no result

Doctrine_Collection|array findAll(int $hydrationMode = null)

Retrieves all the records stored in this table.

Parameters

int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD

Return Value

Doctrine_Collection|array

Doctrine_Collection|array findBySql(string $dql, array $params = array(), int $hydrationMode = null)

Finds records in this table with a given SQL where clause.

Parameters

string $dql DQL WHERE clause to use
array $params query parameters (a la PDO)
int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD

Return Value

Doctrine_Collection|array

Doctrine_Collection|array findByDql(string $dql, array $params = array(), int $hydrationMode = null)

Finds records in this table with a given DQL where clause.

Parameters

string $dql DQL WHERE clause
array $params preparated statement parameters
int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD

Return Value

Doctrine_Collection|array

Doctrine_Collection|array findBy($fieldName, $value, $hydrationMode = null)

Find records basing on a field.

Parameters

$fieldName
$value
$hydrationMode

Return Value

Doctrine_Collection|array

Doctrine_Record findOneBy($fieldName, $value, $hydrationMode = null)

Finds the first record that satisfy the clause.

Parameters

$fieldName
$value
$hydrationMode

Return Value

Doctrine_Record

Doctrine_Collection|array execute(string $queryKey, array $params = array(), int $hydrationMode = Doctrine_Core::HYDRATE_RECORD)

Finds result of a named query.

This method fetches data using the provided $queryKey to choose a named query in the query registry.

Parameters

string $queryKey the query key
array $params prepared statement params (if any)
int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD

Return Value

Doctrine_Collection|array

Exceptions

Doctrine_Query_Registry if no query for given queryKey is found

Doctrine_Record|array executeOne(string $queryKey, array $params = array(), int $hydrationMode = Doctrine_Core::HYDRATE_RECORD)

Fetches one record with a named query.

This method uses the provided $queryKey to clone and execute the associated named query in the query registry.

Parameters

string $queryKey the query key
array $params prepared statement params (if any)
int $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD

Return Value

Doctrine_Record|array

Exceptions

Doctrine_Query_Registry if no query for given queryKey is found

void clear()

Clears the first level cache (identityMap).

This method ensures that records are reloaded from the db.

Return Value

void

boolean addRecord(Doctrine_Record $record)

Adds a record to the first level cache (identity map).

This method is used internally to cache records, ensuring that only one object that represents a sql record exists in all scopes.

Parameters

Doctrine_Record $record record to be added

Return Value

boolean true if record was not present in the map

boolean removeRecord(Doctrine_Record $record)

Removes a record from the identity map.

This method deletes from the cache the given record; can be used to force reloading of an object from database.

Parameters

Doctrine_Record $record record to remove from cache

Return Value

boolean true if the record was found and removed, false if the record wasn't found.

Doctrine_Record getRecord()

Returns a new record.

This method checks if a internal record exists in identityMap, if does not exist it creates a new one.

Return Value

Doctrine_Record

string getClassnameToReturn() deprecated

deprecated

Get the classname to return. Most often this is just the options['name'].

Check the subclasses option and the inheritanceMap for each subclass to see if all the maps in a subclass is met. If this is the case return that subclass name. If no subclasses match or if there are no subclasses defined return the name of the class for this tables record.

Return Value

string The name of the class to create

final Doctrine_Record getProxy($id = null)

Parameters

$id database row id

Return Value

Doctrine_Record

Exceptions

Doctrine_Find_Exception

final string applyInheritance($where)

applyInheritance

Parameters

$where query where part to be modified

Return Value

string query where part with column aggregation inheritance added

integer count()

Implements Countable interface.

Return Value

integer number of records in the table

Doctrine_Query getQueryObject()

Return Value

Doctrine_Query a Doctrine_Query object

array getEnumValues(string $fieldName)

Retrieves the enum values for a given field.

Parameters

string $fieldName

Return Value

array

mixed enumValue(string $fieldName, integer $index)

Retrieves an enum value.

This method finds a enum string value. If ATTR_USE_NATIVE_ENUM is set on the connection, index and value are the same thing.

Parameters

string $fieldName
integer $index numeric index of the enum

Return Value

mixed

integer enumIndex(string $fieldName, mixed $value)

Retrieves an enum index.

Parameters

string $fieldName
mixed $value value of the enum considered

Return Value

integer can be string if native enums are used.

See also

enumValue()

Doctrine_Validator_ErrorStack validateField(string $fieldName, string $value, Doctrine_Record $record = null)

Validates a given field using table ATTR_VALIDATE rules.

Parameters

string $fieldName
string $value
Doctrine_Record $record record to consider; if it does not exists, it is created

Return Value

Doctrine_Validator_ErrorStack $errorStack

See also

Doctrine_Core::ATTR_VALIDATE

validateUniques(Doctrine_Record $record)

Validates all the unique indexes.

This methods validates 'unique' sets of fields for the given Doctrine_Record instance. Pushes error to the record error stack if they are generated.

Parameters

Doctrine_Record $record

integer getColumnCount()

Return Value

integer the number of columns in this table

array getColumns()

Retrieves all columns of the table.

Return Value

array keys are column names and values are definition

See also

$_columns;

boolean removeColumn(string $fieldName)

Removes a field name from the table schema information.

Parameters

string $fieldName

Return Value

boolean true if the field is found and removed. False otherwise.

array getColumnNames(array $fieldNames = null)

Returns an array containing all the column names.

Parameters

array $fieldNames

Return Value

array numeric array

array getIdentifierColumnNames()

Returns an array with all the identifier column names.

Return Value

array numeric array

array getUniques()

Gets the array of unique fields sets.

Return Value

array numeric array

See also

$_uniques;

array getFieldNames()

Returns an array containing all the field names.

Return Value

array numeric array

array getDefinitionOf(string $fieldName)

Retrieves the definition of a field.

This method retrieves the definition of the column, basing of $fieldName which can be a column name or a field name (alias).

Parameters

string $fieldName

Return Value

array false on failure

string getTypeOf(string $fieldName)

Retrieves the type of a field.

Parameters

string $fieldName

Return Value

string false on failure

string getTypeOfColumn(string $columnName)

Retrieves the type of a column.

Parameters

string $columnName

Return Value

string false if column is not found

void setData(array $data)

Doctrine uses this function internally.

Users are strongly discouraged to use this function.

Parameters

array $data internal data

Return Value

void

array getData()

Returns internal data.

This method is used by Doctrine_Record instances when retrieving data from database.

Return Value

array

mixed prepareValue($fieldName, $value, $typeHint = null)

Performs special data preparation.

This method returns a representation of a field data, depending on the type of the given column.

  1. It unserializes array and object typed columns
  2. Uncompresses gzip typed columns
  3. Initializes special null object pointer for null values (for fast column existence checking purposes)

example: $field = 'name'; $value = null; $table->prepareValue($field, $value); // Doctrine_Null

Parameters

$fieldName
$value
$typeHint

Return Value

mixed prepared value

Exceptions

Doctrine_Table_Exception if unserialization of array/object typed column fails or
Doctrine_Table_Exception if uncompression of gzip typed column fails *

Doctrine_Tree getTree()

Gets associated tree.

This method returns the associated Tree object (if any exists). Normally implemented by NestedSet behavior.

Return Value

Doctrine_Tree false if not a tree

string getComponentName()

Gets the subclass of Doctrine_Record that belongs to this table.

Return Value

string

string getTableName()

Gets the table name in the db.

Return Value

string

void setTableName(string $tableName)

sets the table name in the schema definition.

Parameters

string $tableName

Return Value

void

boolean isTree()

Determines if table acts as tree.

Return Value

boolean if tree return true, otherwise returns false

array getTemplates()

Retrieves all templates (behaviors) attached to this table.

Return Value

array an array containing all templates

Doctrine_Template getTemplate(string $template)

Retrieves a particular template by class name.

This method retrieves a behavior/template object attached to the table. For Doctrine_Template_* classes, the base name can be used.

Parameters

string $template name of the behavior

Return Value

Doctrine_Template

Exceptions

Doctrine_Table_Exception if the given template is not set on this table

boolean hasTemplate(string $template)

Checks if the table has a given template.

Parameters

string $template name of template; see getTemplate()

Return Value

boolean

Doctrine_Table addTemplate(string $template, Doctrine_Template $impl)

Adds a template to this table.

Parameters

string $template template name
Doctrine_Template $impl behavior to attach

Return Value

Doctrine_Table

array getGenerators()

Gets all the generators for this table.

Return Value

array $generators

Doctrine_Record_Generator getGenerator(string $generator)

Gets generator instance for a passed name.

Parameters

string $generator

Return Value

Doctrine_Record_Generator $generator

void hasGenerator(string $generator)

Checks if a generator name exists.

Parameters

string $generator

Return Value

void

Doctrine_Table addGenerator(Doctrine_Record_Generator $generator, string $name = null)

Adds a generate to the table instance.

Parameters

Doctrine_Record_Generator $generator
string $name

Return Value

Doctrine_Table

void setGenerator(Doctrine_Record_Generator $generator)

Set the generator responsible for creating this table

Parameters

Doctrine_Record_Generator $generator

Return Value

void

boolean isGenerator()

Check whether this table was created by a record generator or not

Return Value

boolean

Doctrine_Record_Generator getParentGenerator()

Get the parent generator responsible for this table instance

Doctrine_Table bindQueryParts(array $queryParts)

Binds query parts to this component.

Parameters

array $queryParts an array of pre-bound query parts

Return Value

Doctrine_Table this object

See also

bindQueryPart()

Doctrine_Record bindQueryPart(string $queryPart, mixed $value)

Adds default query parts to the selects executed on this table.

This method binds given value to given query part. Every query created by this table will have this part set by default.

Parameters

string $queryPart
mixed $value

Return Value

Doctrine_Record this object

array getFieldValidators(string $fieldName)

Gets the names of all validators being applied on a field.

Parameters

string $fieldName

Return Value

array names of validators

integer getFieldLength(string $fieldName)

Gets the maximum length of a field.

For integer fields, length is bytes occupied. For decimal fields, it is the total number of cyphers

Parameters

string $fieldName

Return Value

integer

string getBoundQueryPart(string $queryPart)

Retrieves a bound query part.

Parameters

string $queryPart field interested

Return Value

string value of the bind

See also

bindQueryPart()

Doctrine_Table unshiftFilter(Doctrine_Record_Filter $filter)

unshiftFilter

Parameters

Doctrine_Record_Filter $filter

Return Value

Doctrine_Table this object (provides a fluent interface)

array getFilters()

getFilters

Return Value

array $filters

string __toString()

Generates a string representation of this object.

This method is useful for debugging purposes, or it can be overriden in Doctrine_Record to provide a value when Record is casted to (string).

Return Value

string

buildFindByWhere($fieldName)

Parameters

$fieldName

protected string _resolveFindByFieldName(string $name)

Resolves the passed find by field name inflecting the parameter.

This method resolves the appropriate field name regardless of whether the user passes a column name, field name, or a Doctrine_Inflector::classified() version of their column name. It will be inflected with Doctrine_Inflector::tableize() to get the column or field name.

Parameters

string $name

Return Value

string $fieldName

the __call($method, $arguments)

Adds support for magic finders.

This method add support for calling methods not defined in code, such as: findByColumnName, findByRelationAlias findById, findByContactId, etc.

Parameters

$method
$arguments

Return Value

the result of the finder