From 7ec25f196ab63e31fb5c52109130c85232b41e92 Mon Sep 17 00:00:00 2001 From: romanb Date: Mon, 12 Oct 2009 12:54:14 +0000 Subject: [PATCH] [2.0] Added missing recognition of the 'fetch' attribute in metadata drivers. --- .../ORM/Mapping/AssociationMapping.php | 4 +++- .../ORM/Mapping/Driver/AnnotationDriver.php | 4 ++++ .../ORM/Mapping/Driver/DoctrineAnnotations.php | 8 ++++---- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 18 +++++++++++++++++- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 16 ++++++++++++++++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php index 7e13e6ad3..fd897462f 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php +++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php @@ -72,7 +72,7 @@ abstract class AssociationMapping * * @var integer */ - public $fetchMode = self::FETCH_LAZY; + public $fetchMode; /** * Flag that indicates whether the class that defines this mapping is @@ -182,6 +182,8 @@ abstract class AssociationMapping // Optional attributes for both sides $this->isOptional = isset($mapping['optional']) ? (bool)$mapping['optional'] : true; + $this->fetchMode = isset($mapping['fetch']) ? + $mapping['fetch'] : self::FETCH_LAZY; $this->cascades = isset($mapping['cascade']) ? (array)$mapping['cascade'] : array(); $this->isCascadeRemove = in_array('remove', $this->cascades); diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 6b0820080..c8ceaef35 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -224,17 +224,20 @@ class AnnotationDriver implements Driver $mapping['mappedBy'] = $oneToOneAnnot->mappedBy; $mapping['cascade'] = $oneToOneAnnot->cascade; $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval; + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToOneAnnot->fetch); $metadata->mapOneToOne($mapping); } else if ($oneToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToMany')) { $mapping['mappedBy'] = $oneToManyAnnot->mappedBy; $mapping['targetEntity'] = $oneToManyAnnot->targetEntity; $mapping['cascade'] = $oneToManyAnnot->cascade; $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval; + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToManyAnnot->fetch); $metadata->mapOneToMany($mapping); } else if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) { $mapping['joinColumns'] = $joinColumns; $mapping['cascade'] = $manyToOneAnnot->cascade; $mapping['targetEntity'] = $manyToOneAnnot->targetEntity; + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToOneAnnot->fetch); $metadata->mapManyToOne($mapping); } else if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) { $joinTable = array(); @@ -272,6 +275,7 @@ class AnnotationDriver implements Driver $mapping['targetEntity'] = $manyToManyAnnot->targetEntity; $mapping['mappedBy'] = $manyToManyAnnot->mappedBy; $mapping['cascade'] = $manyToManyAnnot->cascade; + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToManyAnnot->fetch); $metadata->mapManyToMany($mapping); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php index cd287f01b..e6a2f3226 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php @@ -68,7 +68,7 @@ final class OneToOne extends Annotation { public $targetEntity; public $mappedBy; public $cascade; - public $fetch; + public $fetch = 'LAZY'; public $optional; public $orphanRemoval = false; } @@ -76,20 +76,20 @@ final class OneToMany extends Annotation { public $mappedBy; public $targetEntity; public $cascade; - public $fetch; + public $fetch = 'LAZY'; public $orphanRemoval = false; } final class ManyToOne extends Annotation { public $targetEntity; public $cascade; - public $fetch; + public $fetch = 'LAZY'; public $optional; } final class ManyToMany extends Annotation { public $targetEntity; public $mappedBy; public $cascade; - public $fetch; + public $fetch = 'LAZY'; } final class ElementCollection extends Annotation { public $tableName; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 0a48834d0..d3a9949f0 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -195,9 +195,13 @@ class XmlDriver extends AbstractFileDriver foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) { $mapping = array( 'fieldName' => (string)$oneToOneElement['field'], - 'targetEntity' => (string)$oneToOneElement['target-entity'], + 'targetEntity' => (string)$oneToOneElement['target-entity'] ); + if (isset($oneToOneElement['fetch'])) { + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . (string)$oneToOneElement['fetch']); + } + if (isset($oneToOneElement['mapped-by'])) { $mapping['mappedBy'] = (string)$oneToOneElement['mapped-by']; } else { @@ -237,6 +241,10 @@ class XmlDriver extends AbstractFileDriver 'mappedBy' => (string)$oneToManyElement['mapped-by'] ); + if (isset($oneToManyElement['fetch'])) { + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . (string)$oneToManyElement['fetch']); + } + if (isset($oneToManyElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade); } @@ -257,6 +265,10 @@ class XmlDriver extends AbstractFileDriver 'targetEntity' => (string)$manyToOneElement['target-entity'] ); + if (isset($manyToOneElement['fetch'])) { + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . (string)$manyToOneElement['fetch']); + } + $joinColumns = array(); if (isset($manyToOneElement->{'join-column'})) { @@ -295,6 +307,10 @@ class XmlDriver extends AbstractFileDriver 'targetEntity' => (string)$manyToManyElement['target-entity'] ); + if (isset($manyToManyElement['fetch'])) { + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . (string)$manyToManyElement['fetch']); + } + if (isset($manyToManyElement['mappedBy'])) { $mapping['mappedBy'] = (string)$manyToManyElement['mapped-by']; } else if (isset($manyToManyElement->{'join-table'})) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 8bce76fad..822bf7b7c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -208,6 +208,10 @@ class YamlDriver extends AbstractFileDriver 'targetEntity' => $oneToOneElement['targetEntity'] ); + if (isset($oneToOneElement['fetch'])) { + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToOneElement['fetch']); + } + if (isset($oneToOneElement['mappedBy'])) { $mapping['mappedBy'] = $oneToOneElement['mappedBy']; } else { @@ -247,6 +251,10 @@ class YamlDriver extends AbstractFileDriver 'mappedBy' => $oneToManyElement['mappedBy'] ); + if (isset($oneToManyElement['fetch'])) { + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $oneToManyElement['fetch']); + } + if (isset($oneToManyElement['cascade'])) { $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement['cascade']); } @@ -263,6 +271,10 @@ class YamlDriver extends AbstractFileDriver 'targetEntity' => $manyToOneElement['targetEntity'] ); + if (isset($manyToOneElement['fetch'])) { + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToOneElement['fetch']); + } + $joinColumns = array(); if (isset($manyToOneElement['joinColumn'])) { @@ -297,6 +309,10 @@ class YamlDriver extends AbstractFileDriver 'targetEntity' => $manyToManyElement['targetEntity'] ); + if (isset($manyToManyElement['fetch'])) { + $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToManyElement['fetch']); + } + if (isset($manyToManyElement['mappedBy'])) { $mapping['mappedBy'] = $manyToManyElement['mappedBy']; } else if (isset($manyToManyElement['joinTable'])) {