Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 09441bf

Browse files
authored
Merge pull request #54 from niels-nijens/reference-type-control
Add configuration options for (inverse-)reference type
2 parents e47d427 + 7baf70a commit 09441bf

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

Resources/xsl/doctrine-mapping.xsl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,15 @@
201201
Don't add an entity reference for a field that has a @datatype starting with 'OBJECT.'.
202202
-->
203203
<xsl:template match='object/fields/field[starts-with(@datatype, "OBJECT.")]' mode='fieldEntityReference'>
204-
<xsl:element name='many-to-one' namespace='http://doctrine-project.org/schemas/orm/doctrine-mapping'>
204+
<xsl:variable name='fieldName' select='@name'/>
205+
<xsl:variable name='referenceType'>
206+
<xsl:choose>
207+
<xsl:when test='parent::fields/parent::object/orm/reference[@name = $fieldName]'><xsl:value-of select='parent::fields/parent::object/orm/reference[@name = $fieldName]/@type'/></xsl:when>
208+
<xsl:otherwise>many-to-one</xsl:otherwise>
209+
</xsl:choose>
210+
</xsl:variable>
211+
212+
<xsl:element name='{$referenceType}' namespace='http://doctrine-project.org/schemas/orm/doctrine-mapping'>
205213
<xsl:attribute name='field'><xsl:value-of select='@name'/></xsl:attribute>
206214
<xsl:attribute name='target-entity'><xsl:value-of select='substring(@datatype, 8)'/></xsl:attribute>
207215
<xsl:if test='/flexmodel/object[@name = substring(current()/@datatype, 8)]/orm/inverse-reference[@object = current()/parent::fields/parent::object/@name]/@name'>
@@ -211,10 +219,17 @@
211219
</xsl:template>
212220

213221
<!--
214-
Add inverse references if defined
222+
Add inverse references if defined.
215223
-->
216224
<xsl:template match='object/orm/inverse-reference' mode='inverseReferences'>
217-
<xsl:element name='one-to-many' namespace='http://doctrine-project.org/schemas/orm/doctrine-mapping'>
225+
<xsl:variable name='referenceType'>
226+
<xsl:choose>
227+
<xsl:when test='@type'><xsl:value-of select='@type'/></xsl:when>
228+
<xsl:otherwise>one-to-many</xsl:otherwise>
229+
</xsl:choose>
230+
</xsl:variable>
231+
232+
<xsl:element name='{$referenceType}' namespace='http://doctrine-project.org/schemas/orm/doctrine-mapping'>
218233
<xsl:attribute name='field'><xsl:value-of select='@name'/></xsl:attribute>
219234
<xsl:attribute name='target-entity'><xsl:value-of select='@object'/></xsl:attribute>
220235
<xsl:attribute name='mapped-by'><xsl:value-of select='@field'/></xsl:attribute>

0 commit comments

Comments
 (0)