You are currently reading the 1.2 documentation. Switch to 2.2  2.1  2.0 

Naming convention attributes

Naming convention attributes affect the naming of different database related elements such as tables, indexes and sequences. Basically every naming convention attribute has affect in both ways. When importing schemas from the database to classes and when exporting classes into database tables.

So for example by default Doctrine naming convention for indexes is %s_idx. Not only do the indexes you set get a special suffix, also the imported classes get their indexes mapped to their non-suffixed equivalents. This applies to all naming convention attributes.

Index name format

Doctrine_Core::ATTR_IDXNAME_FORMAT can be used for changing the naming convention of indexes. By default Doctrine uses the format [name]_idx. So defining an index called 'ageindex' will actually be converted into 'ageindex_idx'.

You can change the index naming convention with the following code:

// bootstrap.php

// ...
$manager->setAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT, '%s_index');

Sequence name format

Similar to Doctrine_Core::ATTR_IDXNAME_FORMAT, Doctrine_Core::ATTR_SEQNAME_FORMAT can be used for changing the naming convention of sequences. By default Doctrine uses the format [name]_seq, hence creating a new sequence with the name of mysequence will lead into creation of sequence called mysequence_seq.

You can change the sequence naming convention with the following code:

// bootstrap.php

// ...
$manager->setAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT, '%s_sequence');

Table name format

The table name format can be changed the same as the index and sequence name format with the following code:

// bootstrap.php

// ...
$manager->setAttribute(Doctrine_Core::ATTR_TBLNAME_FORMAT, '%s_table');

Database name format

The database name format can be changed the same as the index, sequence and table name format with the following code:

// bootstrap.php

// ...
$manager->setAttribute(Doctrine_Core::ATTR_DBNAME_FORMAT, 'myframework_%s');

Validation attributes

Doctrine provides complete control over what it validates. The validation procedure can be controlled with Doctrine_Core::ATTR_VALIDATE.

The validation modes are bitwised, so they can be combined using | and removed using ^. See the examples section below on how to do this.

Validation mode constants

Name Description
VALIDATE_NONE Turns off the whole validation procedure.
VALIDATE_LENGTHS Makes Doctrine validate all field lengths.
VALIDATE_TYPES Makes Doctrine validate all field types. Doctrine does loose type validation. This means that for example string with value '13.3' will not pass as an integer but '13' will.
VALIDATE_CONSTRAINTS Makes Doctrine validate all field constraints such as notnull, email etc.
VALIDATE_ALL Turns on all validations.

Validation by default is turned off so if you wish for your data to be validated you will need to enable it. Some examples of how to change this configuration are provided below.

Examples

You can turn on all validations by using the Doctrine_Core::VALIDATE_ALL attribute with the following code:

// bootstrap.php

// ...
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);

You can also configure Doctrine to validate lengths and types, but not constraints with the following code:

// bootstrap.php

// ...
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE,
  Doctrine_Core::VALIDATE_LENGTHS | Doctrine_Core::VALIDATE_TYPES);

Questions and Feedback

If you find a problem with the documentation or have a suggestion, please register and open a ticket.

If you need support or have a technical question, you can post to the user mailing-list.