Skip to content

Commit

Permalink
Fix issue with association made of multiple names
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Jun 1, 2014
1 parent b0103a3 commit 4809c55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.3.3

* Fix an issue with camelCased associations when rendering a resource

## 0.3.2

* Added support for OneToOne association (assuming you have a "User" entity with a OneToOne association to
Expand Down
16 changes: 9 additions & 7 deletions src/ZfrRest/View/Renderer/DefaultResourceRenderer.php
Expand Up @@ -191,13 +191,15 @@ protected function renderAssociations(array $data, ResourceMetadataInterface $re
$associations = $classMetadata->getAssociationNames();

foreach ($associations as $association) {
$inflectedAssociation = $association;

if ($this->underscoreSeparatedKeys) {
$association = strtolower($inflector->filter($association));
$inflectedAssociation = strtolower($inflector->filter($association));
}

// If the association object is not in the payload or is not defined in mapping... we cannot do anything
if (!isset($data[$association]) || !$resourceMetadata->hasAssociationMetadata($association)) {
unset($data[$association]);
if (!isset($data[$inflectedAssociation]) || !$resourceMetadata->hasAssociationMetadata($association)) {
unset($data[$inflectedAssociation]);
continue;
}

Expand All @@ -208,7 +210,7 @@ protected function renderAssociations(array $data, ResourceMetadataInterface $re

// If set to NONE, we don't even want the association to be in the payload
if ($extractionStrategy === ResourceMetadataInterface::ASSOCIATION_EXTRACTION_NONE) {
unset($data[$association]);
unset($data[$inflectedAssociation]);
continue;
}

Expand All @@ -218,9 +220,9 @@ protected function renderAssociations(array $data, ResourceMetadataInterface $re
}

// Otherwise, we render the association
$isCollectionValued = $classMetadata->isCollectionValuedAssociation($association);
$data[$association] = $this->renderAssociation(
$data[$association],
$isCollectionValued = $classMetadata->isCollectionValuedAssociation($association);
$data[$inflectedAssociation] = $this->renderAssociation(
$data[$inflectedAssociation],
$classMetadata->getAssociationTargetClass($association),
$extractionStrategy,
$isCollectionValued
Expand Down

0 comments on commit 4809c55

Please sign in to comment.