More association mapping yml+xml code blocks
This commit is contained in:
parent
c187862e4f
commit
41600667c2
@ -915,7 +915,9 @@ Real many-to-many associations are less common. The following
|
|||||||
example shows a unidirectional association between User and Group
|
example shows a unidirectional association between User and Group
|
||||||
entities:
|
entities:
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
@ -945,6 +947,39 @@ entities:
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="User">
|
||||||
|
<many-to-many field="groups" target-entity="Group">
|
||||||
|
<join-table name="users_groups">
|
||||||
|
<join-columns>
|
||||||
|
<join-column="user_id" referenced-column-name="id" />
|
||||||
|
</join-columns>
|
||||||
|
<inverse-join-columns>
|
||||||
|
<join-column="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: users_groups
|
||||||
|
joinColumns:
|
||||||
|
user_id:
|
||||||
|
referencedColumnName: id
|
||||||
|
inverseJoinColumns:
|
||||||
|
group_id:
|
||||||
|
referencedColumnName: id
|
||||||
|
|
||||||
Generated MySQL Schema:
|
Generated MySQL Schema:
|
||||||
|
|
||||||
.. code-block:: sql
|
.. code-block:: sql
|
||||||
@ -980,7 +1015,9 @@ Many-To-Many, Bidirectional
|
|||||||
Here is a similar many-to-many relationship as above except this
|
Here is a similar many-to-many relationship as above except this
|
||||||
one is bidirectional.
|
one is bidirectional.
|
||||||
|
|
||||||
.. code-block:: php
|
.. configuration-block::
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
/** @Entity */
|
/** @Entity */
|
||||||
@ -990,10 +1027,7 @@ one is bidirectional.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ManyToMany(targetEntity="Group", inversedBy="users")
|
* @ManyToMany(targetEntity="Group", inversedBy="users")
|
||||||
* @JoinTable(name="users_groups",
|
* @JoinTable(name="users_groups")
|
||||||
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
|
|
||||||
* inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
|
|
||||||
* )
|
|
||||||
*/
|
*/
|
||||||
private $groups;
|
private $groups;
|
||||||
|
|
||||||
@ -1020,6 +1054,51 @@ one is bidirectional.
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
<doctrine-mapping>
|
||||||
|
<entity name="User">
|
||||||
|
<many-to-many field="groups" inversed-by="users">
|
||||||
|
<join-table name="users_groups">
|
||||||
|
<join-columns>
|
||||||
|
<join-column="user_id" referenced-column-name="id" />
|
||||||
|
</join-columns>
|
||||||
|
<inverse-join-columns>
|
||||||
|
<join-column="group_id" referenced-column-name="id" />
|
||||||
|
</inverse-join-columns>
|
||||||
|
</join-table>
|
||||||
|
</many-to-many>
|
||||||
|
</entity>
|
||||||
|
|
||||||
|
<entity name="Group">
|
||||||
|
<many-to-many field="users" mapped-by="groups" />
|
||||||
|
</entity>
|
||||||
|
</doctrine-mapping>
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
User:
|
||||||
|
type: entity
|
||||||
|
manyToMany:
|
||||||
|
groups:
|
||||||
|
targetEntity: Group
|
||||||
|
inversedBy: users
|
||||||
|
joinTable:
|
||||||
|
name: users_groups
|
||||||
|
joinColumns:
|
||||||
|
user_id:
|
||||||
|
referencedColumnName: id
|
||||||
|
inverseJoinColumns:
|
||||||
|
group_id:
|
||||||
|
referencedColumnName: id
|
||||||
|
|
||||||
|
Group:
|
||||||
|
type: entity
|
||||||
|
manyToMany:
|
||||||
|
users:
|
||||||
|
targetEntity: User
|
||||||
|
mappedBy: groups
|
||||||
|
|
||||||
The MySQL schema is exactly the same as for the Many-To-Many
|
The MySQL schema is exactly the same as for the Many-To-Many
|
||||||
uni-directional case above.
|
uni-directional case above.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user