Add tons of xml and yaml configuration blocks to basic- and association-mapping chapters
This commit is contained in:
parent
6816816101
commit
b5827ea83f
@ -133,57 +133,151 @@ follows:
|
|||||||
|
|
||||||
As an example, consider this mapping:
|
As an example, consider this mapping:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
/** @OneToOne(targetEntity="Shipping") */
|
|
||||||
private $shipping;
|
<?php
|
||||||
|
/** @OneToOne(targetEntity="Shipping") */
|
||||||
|
private $shipping;
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity class="Product">
|
||||||
|
<one-to-one field="shipping" target-entity="Shipping" />
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
Product:
|
||||||
|
type: entity
|
||||||
|
oneToOne:
|
||||||
|
shipping:
|
||||||
|
targetEntity: Shipping
|
||||||
|
|
||||||
This is essentially the same as the following, more verbose,
|
This is essentially the same as the following, more verbose,
|
||||||
mapping:
|
mapping:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
/**
|
|
||||||
* @OneToOne(targetEntity="Shipping")
|
<?php
|
||||||
* @JoinColumn(name="shipping_id", referencedColumnName="id")
|
/**
|
||||||
*/
|
* @OneToOne(targetEntity="Shipping")
|
||||||
private $shipping;
|
* @JoinColumn(name="shipping_id", referencedColumnName="id")
|
||||||
|
*/
|
||||||
|
private $shipping;
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity class="Product">
|
||||||
|
<one-to-one field="shipping" target-entity="Shipping">
|
||||||
|
<join-column name="shipping_id" referenced-column-name="id" />
|
||||||
|
</one-to-one>
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
Product:
|
||||||
|
type: entity
|
||||||
|
oneToOne:
|
||||||
|
shipping:
|
||||||
|
targetEntity: Shipping
|
||||||
|
joinColumn:
|
||||||
|
name: shipping_id
|
||||||
|
referencedColumnName: id
|
||||||
|
|
||||||
The @JoinTable definition used for many-to-many mappings has
|
The @JoinTable definition used for many-to-many mappings has
|
||||||
similar defaults. As an example, consider this mapping:
|
similar defaults. As an example, consider this mapping:
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-configuration::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
class User
|
|
||||||
{
|
<?php
|
||||||
//...
|
class User
|
||||||
/** @ManyToMany(targetEntity="Group") */
|
{
|
||||||
private $groups;
|
//...
|
||||||
//...
|
/** @ManyToMany(targetEntity="Group") */
|
||||||
}
|
private $groups;
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity class="User">
|
||||||
|
<many-to-many field="groups" target-entity="Group" />
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
User:
|
||||||
|
type: entity
|
||||||
|
manyToMany:
|
||||||
|
groups:
|
||||||
|
targetEntity: Group
|
||||||
|
|
||||||
This is essentially the same as the following, more verbose,
|
This is essentially the same as the following, more verbose,
|
||||||
mapping:
|
mapping:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
class User
|
|
||||||
{
|
<?php
|
||||||
//...
|
class User
|
||||||
/**
|
{
|
||||||
* @ManyToMany(targetEntity="Group")
|
//...
|
||||||
* @JoinTable(name="User_Group",
|
/**
|
||||||
* joinColumns={@JoinColumn(name="User_id", referencedColumnName="id")},
|
* @ManyToMany(targetEntity="Group")
|
||||||
* inverseJoinColumns={@JoinColumn(name="Group_id", referencedColumnName="id")}
|
* @JoinTable(name="User_Group",
|
||||||
* )
|
* joinColumns={@JoinColumn(name="User_id", referencedColumnName="id")},
|
||||||
*/
|
* inverseJoinColumns={@JoinColumn(name="Group_id", referencedColumnName="id")}
|
||||||
private $groups;
|
* )
|
||||||
//...
|
*/
|
||||||
}
|
private $groups;
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity class="User">
|
||||||
|
<many-to-many field="groups" target-entity="Group">
|
||||||
|
<join-table name="User_Group">
|
||||||
|
<join-columns>
|
||||||
|
<join-column id="User_id" referenced-column-name="id" />
|
||||||
|
</join-columns>
|
||||||
|
<inverse-join-columns>
|
||||||
|
<join-column id="Group_id" referenced-column-name="id" />
|
||||||
|
</inverse-join-columns>
|
||||||
|
</join-table>
|
||||||
|
</many-to-many>
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
User:
|
||||||
|
type: entity
|
||||||
|
manyToMany:
|
||||||
|
groups:
|
||||||
|
targetEntity: Group
|
||||||
|
joinTable:
|
||||||
|
name: User_Group
|
||||||
|
joinColumns:
|
||||||
|
User_id:
|
||||||
|
referencedColumnName: id
|
||||||
|
inverseJoinColumns:
|
||||||
|
Group_id
|
||||||
|
referencedColumnName: id
|
||||||
|
|
||||||
In that case, the name of the join table defaults to a combination
|
In that case, the name of the join table defaults to a combination
|
||||||
of the simple, unqualified class names of the participating
|
of the simple, unqualified class names of the participating
|
||||||
@ -276,6 +370,7 @@ Or you can trigger the validation manually:
|
|||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
|
<?php
|
||||||
use Doctrine\ORM\Tools\SchemaValidator;
|
use Doctrine\ORM\Tools\SchemaValidator;
|
||||||
|
|
||||||
$validator = new SchemaValidator($entityManager);
|
$validator = new SchemaValidator($entityManager);
|
||||||
@ -306,28 +401,51 @@ example of a ``Product`` that has one ``Shipping`` object
|
|||||||
associated to it. The ``Shipping`` side does not reference back to
|
associated to it. The ``Shipping`` side does not reference back to
|
||||||
the ``Product`` so it is unidirectional.
|
the ``Product`` so it is unidirectional.
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
/** @Entity */
|
|
||||||
class Product
|
|
||||||
{
|
|
||||||
// ...
|
|
||||||
|
|
||||||
/**
|
<?php
|
||||||
* @OneToOne(targetEntity="Shipping")
|
/** @Entity */
|
||||||
* @JoinColumn(name="shipping_id", referencedColumnName="id")
|
class Product
|
||||||
*/
|
{
|
||||||
private $shipping;
|
// ...
|
||||||
|
|
||||||
// ...
|
/**
|
||||||
}
|
* @OneToOne(targetEntity="Shipping")
|
||||||
|
* @JoinColumn(name="shipping_id", referencedColumnName="id")
|
||||||
|
*/
|
||||||
|
private $shipping;
|
||||||
|
|
||||||
/** @Entity */
|
// ...
|
||||||
class Shipping
|
}
|
||||||
{
|
|
||||||
// ...
|
/** @Entity */
|
||||||
}
|
class Shipping
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity class="Product">
|
||||||
|
<one-to-one field="shipping" target-entity="Shipping">
|
||||||
|
<join-column name="shipping_id" referenced-column-name="id" />
|
||||||
|
</one-to-one>
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
Product:
|
||||||
|
type: entity
|
||||||
|
oneToOne:
|
||||||
|
shipping:
|
||||||
|
targetEntity: Shipping
|
||||||
|
joinColumn:
|
||||||
|
name: shipping_id
|
||||||
|
referencedColumnName: id
|
||||||
|
|
||||||
Note that the @JoinColumn is not really necessary in this example,
|
Note that the @JoinColumn is not really necessary in this example,
|
||||||
as the defaults would be the same.
|
as the defaults would be the same.
|
||||||
@ -354,35 +472,66 @@ Here is a one-to-one relationship between a ``Customer`` and a
|
|||||||
``Cart``. The ``Cart`` has a reference back to the ``Customer`` so
|
``Cart``. The ``Cart`` has a reference back to the ``Customer`` so
|
||||||
it is bidirectional.
|
it is bidirectional.
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
/** @Entity */
|
|
||||||
class Customer
|
|
||||||
{
|
|
||||||
// ...
|
|
||||||
|
|
||||||
/**
|
<?php
|
||||||
* @OneToOne(targetEntity="Cart", mappedBy="customer")
|
/** @Entity */
|
||||||
*/
|
class Customer
|
||||||
private $cart;
|
{
|
||||||
|
// ...
|
||||||
|
|
||||||
// ...
|
/**
|
||||||
}
|
* @OneToOne(targetEntity="Cart", mappedBy="customer")
|
||||||
|
*/
|
||||||
|
private $cart;
|
||||||
|
|
||||||
/** @Entity */
|
// ...
|
||||||
class Cart
|
}
|
||||||
{
|
|
||||||
// ...
|
|
||||||
|
|
||||||
/**
|
/** @Entity */
|
||||||
* @OneToOne(targetEntity="Customer", inversedBy="cart")
|
class Cart
|
||||||
* @JoinColumn(name="customer_id", referencedColumnName="id")
|
{
|
||||||
*/
|
// ...
|
||||||
private $customer;
|
|
||||||
|
|
||||||
// ...
|
/**
|
||||||
}
|
* @OneToOne(targetEntity="Customer", inversedBy="cart")
|
||||||
|
* @JoinColumn(name="customer_id", referencedColumnName="id")
|
||||||
|
*/
|
||||||
|
private $customer;
|
||||||
|
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="Customer">
|
||||||
|
<one-to-one field="cart" target-entity="Cart" mapped-by="customer" />
|
||||||
|
</entity>
|
||||||
|
<entity name="Cart">
|
||||||
|
<one-to-one field="customer" target-entity="Customer" inversed-by="cart">
|
||||||
|
<join-column name="customer_id" referenced-column-name="id" />
|
||||||
|
</one-to-one>
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
Customer:
|
||||||
|
oneToOne:
|
||||||
|
cart:
|
||||||
|
targetEntity: Cart
|
||||||
|
mappedBy: customer
|
||||||
|
Cart:
|
||||||
|
oneToOne:
|
||||||
|
customer:
|
||||||
|
targetEntity Customer
|
||||||
|
inversedBy: cart
|
||||||
|
joinColumn:
|
||||||
|
customer_id:
|
||||||
|
referencedColumnName: id
|
||||||
|
|
||||||
Note that the @JoinColumn is not really necessary in this example,
|
Note that the @JoinColumn is not really necessary in this example,
|
||||||
as the defaults would be the same.
|
as the defaults would be the same.
|
||||||
|
@ -16,9 +16,11 @@ object-relational mapping metadata:
|
|||||||
- XML
|
- XML
|
||||||
- YAML
|
- YAML
|
||||||
|
|
||||||
This manual usually uses docblock annotations in all the examples
|
This manual usually mentions docblock annotations in all the examples
|
||||||
that are spread throughout all chapters. There are dedicated
|
that are spread throughout all chapters, however for many examples
|
||||||
chapters for XML and YAML mapping, respectively.
|
alternative YAML and XML examples are given aswell. There are dedicated
|
||||||
|
reference chapters for XML and YAML mapping, respectively that explain them
|
||||||
|
in more detail. There is also an Annotation reference chapter.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
@ -56,7 +58,9 @@ annotations support namespaces and nested annotations among other
|
|||||||
things. The Doctrine 2 ORM defines its own set of docblock
|
things. The Doctrine 2 ORM defines its own set of docblock
|
||||||
annotations for supplying object-relational mapping metadata.
|
annotations for supplying object-relational mapping metadata.
|
||||||
|
|
||||||
**NOTE** If you're not comfortable with the concept of docblock
|
.. note::
|
||||||
|
|
||||||
|
If you're not comfortable with the concept of docblock
|
||||||
annotations, don't worry, as mentioned earlier Doctrine 2 provides
|
annotations, don't worry, as mentioned earlier Doctrine 2 provides
|
||||||
XML and YAML alternatives and you could easily implement your own
|
XML and YAML alternatives and you could easily implement your own
|
||||||
favourite mechanism for defining ORM metadata.
|
favourite mechanism for defining ORM metadata.
|
||||||
@ -69,30 +73,63 @@ In order to mark a class for object-relational persistence it needs
|
|||||||
to be designated as an entity. This can be done through the
|
to be designated as an entity. This can be done through the
|
||||||
``@Entity`` marker annotation.
|
``@Entity`` marker annotation.
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
/** @Entity */
|
|
||||||
class MyPersistentClass
|
<?php
|
||||||
{
|
/** @Entity */
|
||||||
//...
|
class MyPersistentClass
|
||||||
}
|
{
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="MyPersistentClass">
|
||||||
|
<!-- ... ->
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
MyPersistentClass:
|
||||||
|
type: entity
|
||||||
|
# ...
|
||||||
|
|
||||||
By default, the entity will be persisted to a table with the same
|
By default, the entity will be persisted to a table with the same
|
||||||
name as the class name. In order to change that, you can use the
|
name as the class name. In order to change that, you can use the
|
||||||
``@Table`` annotation as follows:
|
``@Table`` annotation as follows:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
/**
|
|
||||||
* @Entity
|
<?php
|
||||||
* @Table(name="my_persistent_class")
|
/**
|
||||||
*/
|
* @Entity
|
||||||
class MyPersistentClass
|
* @Table(name="my_persistent_class")
|
||||||
{
|
*/
|
||||||
//...
|
class MyPersistentClass
|
||||||
}
|
{
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="MyPersistentClass" table="my_persistent_class">
|
||||||
|
<!-- ... ->
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
MyPersistentClass:
|
||||||
|
type: entity
|
||||||
|
table: my_persistent_class
|
||||||
|
# ...
|
||||||
|
|
||||||
Now instances of MyPersistentClass will be persisted into a table
|
Now instances of MyPersistentClass will be persisted into a table
|
||||||
named ``my_persistent_class``.
|
named ``my_persistent_class``.
|
||||||
@ -172,18 +209,39 @@ since it is the most flexible.
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
/** @Entity */
|
|
||||||
class MyPersistentClass
|
<?php
|
||||||
{
|
/** @Entity */
|
||||||
/** @Column(type="integer") */
|
class MyPersistentClass
|
||||||
private $id;
|
{
|
||||||
/** @Column(length=50) */
|
/** @Column(type="integer") */
|
||||||
private $name; // type defaults to string
|
private $id;
|
||||||
//...
|
/** @Column(length=50) */
|
||||||
}
|
private $name; // type defaults to string
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="MyPersistentClass">
|
||||||
|
<field name="id" type="integer" />
|
||||||
|
<field name="name" length="50" />
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
MyPersistentClass:
|
||||||
|
type: entity
|
||||||
|
fields:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
name:
|
||||||
|
length: 50
|
||||||
|
|
||||||
In that example we mapped the field ``id`` to the column ``id``
|
In that example we mapped the field ``id`` to the column ``id``
|
||||||
using the mapping type ``integer`` and the field ``name`` is mapped
|
using the mapping type ``integer`` and the field ``name`` is mapped
|
||||||
@ -193,11 +251,30 @@ as the field names. To specify a different name for the column, you
|
|||||||
can use the ``name`` attribute of the Column annotation as
|
can use the ``name`` attribute of the Column annotation as
|
||||||
follows:
|
follows:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
/** @Column(name="db_name") */
|
|
||||||
private $name;
|
<?php
|
||||||
|
/** @Column(name="db_name") */
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="MyPersistentClass">
|
||||||
|
<field name="name" column="db_name" />
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
MyPersistentClass:
|
||||||
|
type: entity
|
||||||
|
fields:
|
||||||
|
name:
|
||||||
|
length: 50
|
||||||
|
column: db_name
|
||||||
|
|
||||||
The Column annotation has some more attributes. Here is a complete
|
The Column annotation has some more attributes. Here is a complete
|
||||||
list:
|
list:
|
||||||
@ -340,15 +417,37 @@ Every entity class needs an identifier/primary key. You designate
|
|||||||
the field that serves as the identifier with the ``@Id`` marker
|
the field that serves as the identifier with the ``@Id`` marker
|
||||||
annotation. Here is an example:
|
annotation. Here is an example:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
class MyPersistentClass
|
|
||||||
{
|
<?php
|
||||||
/** @Id @Column(type="integer") */
|
class MyPersistentClass
|
||||||
private $id;
|
{
|
||||||
//...
|
/** @Id @Column(type="integer") */
|
||||||
}
|
private $id;
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="MyPersistentClass">
|
||||||
|
<id name="id" type="integer" />
|
||||||
|
<field name="name" length="50" />
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
MyPersistentClass:
|
||||||
|
type: entity
|
||||||
|
id:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
fields:
|
||||||
|
name:
|
||||||
|
length: 50
|
||||||
|
|
||||||
Without doing anything else, the identifier is assumed to be
|
Without doing anything else, the identifier is assumed to be
|
||||||
manually assigned. That means your code would need to properly set
|
manually assigned. That means your code would need to properly set
|
||||||
@ -359,17 +458,43 @@ A common alternative strategy is to use a generated value as the
|
|||||||
identifier. To do this, you use the ``@GeneratedValue`` annotation
|
identifier. To do this, you use the ``@GeneratedValue`` annotation
|
||||||
like this:
|
like this:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
class MyPersistentClass
|
|
||||||
{
|
<?php
|
||||||
/**
|
class MyPersistentClass
|
||||||
* @Id @Column(type="integer")
|
{
|
||||||
* @GeneratedValue
|
/**
|
||||||
*/
|
* @Id @Column(type="integer")
|
||||||
private $id;
|
* @GeneratedValue
|
||||||
}
|
*/
|
||||||
|
private $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="MyPersistentClass">
|
||||||
|
<id name="id" type="integer">
|
||||||
|
<generator strategy="AUTO" />
|
||||||
|
</id>
|
||||||
|
<field name="name" length="50" />
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
MyPersistentClass:
|
||||||
|
type: entity
|
||||||
|
id:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
generator:
|
||||||
|
strategy: AUTO
|
||||||
|
fields:
|
||||||
|
name:
|
||||||
|
length: 50
|
||||||
|
|
||||||
This tells Doctrine to automatically generate a value for the
|
This tells Doctrine to automatically generate a value for the
|
||||||
identifier. How this value is generated is specified by the
|
identifier. How this value is generated is specified by the
|
||||||
@ -417,17 +542,45 @@ The Sequence Generator can currently be used in conjunction with
|
|||||||
Oracle or Postgres and allows some additional configuration options
|
Oracle or Postgres and allows some additional configuration options
|
||||||
besides specifying the sequence's name:
|
besides specifying the sequence's name:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
<?php
|
.. code-block:: php
|
||||||
class User {
|
|
||||||
/**
|
<?php
|
||||||
* @Id
|
class User
|
||||||
* @GeneratedValue(strategy="SEQUENCE")
|
{
|
||||||
* @SequenceGenerator(name="tablename_seq", initialValue=1, allocationSize=100)
|
/**
|
||||||
*/
|
* @Id
|
||||||
protected $id = null;
|
* @GeneratedValue(strategy="SEQUENCE")
|
||||||
}
|
* @SequenceGenerator(name="tablename_seq", initialValue=1, allocationSize=100)
|
||||||
|
*/
|
||||||
|
protected $id = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="User">
|
||||||
|
<id name="id" type="integer">
|
||||||
|
<generator strategy="SEQUENCE" />
|
||||||
|
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
|
||||||
|
</id>
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
MyPersistentClass:
|
||||||
|
type: entity
|
||||||
|
id:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
generator:
|
||||||
|
strategy: SEQUENCE
|
||||||
|
sequenceGenerator:
|
||||||
|
sequenceName: tablename_seq
|
||||||
|
allocationSize: 100
|
||||||
|
initialValue: 1
|
||||||
|
|
||||||
The initial value specifies at which value the sequence should
|
The initial value specifies at which value the sequence should
|
||||||
start.
|
start.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user