/**
* @var Tx_Extbase_Persistence_QOM_QueryObjectModelFactory
*/
- protected $QOMFactory;
+ protected $QomFactory;
/**
* @var Tx_Extbase_Persistence_Session
}
/**
- * Injects the persistence manager
+ * Injects the persistence session
*
- * @param Tx_Extbase_Persistence_ManagerInterface $persistenceManager
+ * @param Tx_Extbase_Persistence_Session $persistenceSession
* @return void
*/
- public function injectPersistenceManager(Tx_Extbase_Persistence_ManagerInterface $persistenceManager) {
- $this->QOMFactory = $persistenceManager->getBackend()->getQOMFactory();
- $this->persistenceSession = $persistenceManager->getSession();
+ public function injectSession(Tx_Extbase_Persistence_Session $persistenceSession) {
+ $this->persistenceSession = $persistenceSession;
}
/**
public function injectReflectionService(Tx_Extbase_Reflection_Service $reflectionService) {
$this->reflectionService = $reflectionService;
}
+
+ /**
+ * Sets the query object model factory
+ *
+ * @param Tx_Extbase_Persistence_QOM_QueryObjectModelFactory $qomFactory
+ * @return void
+ */
+ public function setQomFactory(Tx_Extbase_Persistence_QOM_QueryObjectModelFactory $qomFactory) {
+ $this->qomFactory = $qomFactory;
+ }
/**
* Maps the (aggregate root) rows and registers them as reconstituted
$columnMap = $dataMap->getColumnMap($propertyName);
$columnName = $columnMap->getColumnName();
$propertyValue = NULL;
- $propertyType = $columnMap->getPropertyType();
+
+ $propertyMetaData = $this->reflectionService->getClassSchema($className)->getProperty($propertyName);
+ $propertyType = Tx_Extbase_Persistence_PropertyType::valueFromType($propertyMetaData['type']);
+
+ if ($propertyType == Tx_Extbase_Persistence_PropertyType::UNDEFINED) {
+ $propertyType = $columnMap->getPropertyType();
+ }
+
switch ($propertyType) {
case Tx_Extbase_Persistence_PropertyType::STRING;
case Tx_Extbase_Persistence_PropertyType::DATE;
}
break;
case (Tx_Extbase_Persistence_PropertyType::REFERENCE):
- if (is_null($row->getValue($columnName))) {
- $propertyValue = NULL;
- } else {
- $fieldValue = $row->getValue($columnMap->getColumnName());
+ $propertyValue = $row->getValue($columnName);
+ if (!is_null($propertyValue)) {
+ $fieldValue = $row->getValue($columnName);
$result = $this->fetchRelated($object, $propertyName, $fieldValue);
$propertyValue = $this->mapResultToPropertyValue($object, $propertyName, $result);
}
$childSortByFieldName = $columnMap->getChildSortByFieldName();
if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
$query = $queryFactory->create($this->getType($parentObject, $propertyName));
- $query->matching($query->withUid(intval($fieldValue)));
+ if (isset($parentKeyFieldName)) {
+ $query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()));
+ } else {
+ $query->matching($query->withUid(intval($fieldValue)));
+ }
} elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
$query = $queryFactory->create($this->getElementType($parentObject, $propertyName));
// TODO: This is an ugly hack, just ignoring the storage page state from here. Actually, the query settings would have to be passed into the DataMapper, so we can respect
// enableFields and storage page settings.
$query->getQuerySettings()->setRespectStoragePage(FALSE);
$relationTableName = $columnMap->getRelationTableName();
- $left = $this->QOMFactory->selector(NULL, $relationTableName);
+ $left = $this->qomFactory->selector(NULL, $relationTableName);
$childClassName = $this->getElementType($parentObject, $propertyName);
$childTableName = $columnMap->getChildTableName();
- $right = $this->QOMFactory->selector($childClassName, $childTableName);
- $joinCondition = $this->QOMFactory->equiJoinCondition($relationTableName, $columnMap->getChildKeyFieldName(), $childTableName, 'uid');
- $source = $this->QOMFactory->join(
+ $right = $this->qomFactory->selector($childClassName, $childTableName);
+ $joinCondition = $this->qomFactory->equiJoinCondition($relationTableName, $columnMap->getChildKeyFieldName(), $childTableName, 'uid');
+ $source = $this->qomFactory->join(
$left,
$right,
Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_INNER,
$joinCondition
);
+
$query->setSource($source);
if (!empty($childSortByFieldName)) {
$query->setOrderings(array($relationTableName . '.' . $childSortByFieldName => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));
}
- $query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()));
+
+ // attempt to support MM_match_fields
+ $conditions = $query->equals($parentKeyFieldName, $parentObject->getUid());
+
+ $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
+ if (count($relationTableMatchFields)) {
+ foreach($relationTableMatchFields as $relationTableMatchFieldName => $relationTableMatchFieldValue) {
+ $relationMatchCondition = $query->equals($relationTableName . '.' . $relationTableMatchFieldName, $relationTableMatchFieldValue);
+ $conditions = $query->logicalAnd($conditions, $relationMatchCondition);
+ }
+ }
+ $query->matching($conditions);
+
} else {
throw new Tx_Extbase_Persistence_Exception('Could not determine type of relation.', 1252502725);
}
} else {
throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('Could not determine the child object object type.', 1251315967);
}
- return $elementType;
+ return $elementType;
}
/**