1
0
mirror of synced 2024-12-15 23:56:02 +03:00

Update docs on using own types, aswell as on using Collection::clear()

This commit is contained in:
Benjamin Eberlei 2010-07-03 16:57:02 +02:00
parent 8e7385ccc2
commit 80fd691880
2 changed files with 22 additions and 0 deletions

View File

@ -71,6 +71,8 @@ For example, the Doctrine Mapping Type `string` defines the mapping from a PHP s
* `time`: Type that maps an SQL TIME to a PHP DateTime object. * `time`: Type that maps an SQL TIME to a PHP DateTime object.
* `datetime`: Type that maps an SQL DATETIME/TIMESTAMP to a PHP DateTime object. * `datetime`: Type that maps an SQL DATETIME/TIMESTAMP to a PHP DateTime object.
* `text`: Type that maps an SQL CLOB to a PHP string. * `text`: Type that maps an SQL CLOB to a PHP string.
* `object`: Type that maps a SQL CLOB to a PHP object using `serialize()` and `unserialize()`
* `array`: Type that maps a SQL CLOB to a PHP object using `serialize()` and `unserialize()`
> **NOTE** > **NOTE**
> Doctrine Mapping Types are NOT SQL types and NOT PHP types! They are mapping types > Doctrine Mapping Types are NOT SQL types and NOT PHP types! They are mapping types
@ -189,6 +191,17 @@ for the mapping type and map that to the corresponding fully qualified class nam
private $field; private $field;
} }
To have Schema-Tool convert the underlying database type of your new "mytype" directly into an instance of `MyType`
you have to additionally register this mapping with your database platform:
[php]
$conn = $em->getConnection();
$conn->getDatabasePlatform()->registerDoctrineTypeMapping('db_mytype', 'mytype');
Now using Schema-Tool, whenever it detects a column having the `db_mytype` it will convert it into a `mytype`
Doctrine Type instance for Schema representation. Keep in mind that you can easily produce clashes this way,
each database type can only map to exactly one Doctrine mapping type.
++ Identifiers / Primary Keys ++ Identifiers / Primary Keys
Every entity class needs an identifier/primary key. You designate the field that serves as the identifier with the `@Id` marker annotation. Here is an example: Every entity class needs an identifier/primary key. You designate the field that serves as the identifier with the `@Id` marker annotation. Here is an example:

View File

@ -256,6 +256,15 @@ that has O(n) complexity, where n is the size of the map.
Since Doctrine always only looks at the owning side of a bidirectional association, it is essentially not necessary that an inverse collection of a bidirectional one-to-many or many-to-many association is updated. This knowledge can often be used to improve performance by avoiding the loading of the inverse collection. Since Doctrine always only looks at the owning side of a bidirectional association, it is essentially not necessary that an inverse collection of a bidirectional one-to-many or many-to-many association is updated. This knowledge can often be used to improve performance by avoiding the loading of the inverse collection.
> **NOTE*
>
> You can also clear the contents of a whole collection using the `Collections::clear()` method. You
> should be aware that using this method can lead to a straight and optimized database delete or update call
> during the flush operation that is not aware of entities that have been re-added to the collection.
>
> Say you clear a collection of tags by calling `$post->getTags()->clear();` and then call
> `$post->getTags()->add($tag)`. This will not recognize tag being already added before and issue
> two database calls.
++ Association Management Methods ++ Association Management Methods