Skip to content

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented May 25, 2016

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #551
License MIT
Doc PR
#550 ref (sorry about multiple PR, github was buggy).


return array_map(function ($identifierName, $identifierValue) {
return sprintf('%s=%s', $identifierName, $this->generateIdentifiersUrl($identifierValue));
}, array_keys($identifiers), $identifiers);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fond of this, does anyone have a better idea in mind?

@teohhanhui
Copy link
Contributor

Can you explain what's going on here?

What did you mean when you said:

This was working before #533

I don't see how that can be the case from the code before #533 -

/**
* {@inheritdoc}
*/
public function getIriFromItem($item, int $referenceType = UrlGeneratorInterface::ABS_PATH) : string
{
$resourceClass = $this->getObjectClass($item);
$routeName = $this->getRouteName($resourceClass, false);
$identifierValues = [];
foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $propertyName) {
$propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
if ($propertyMetadata->isIdentifier()) {
$identifierValues[] = $this->propertyAccessor->getValue($item, $propertyName);
}
}
return $this->router->generate($routeName, ['id' => implode('-', $identifierValues)], $referenceType);
}

We never checked for relations when getting identifier values.

@teohhanhui
Copy link
Contributor

Anyway, for fixing this, why don't we just get the id from the entity if it's a relation? Like @Simperfit suggested...

@soyuka
Copy link
Member Author

soyuka commented May 26, 2016

😕 I can't say why it was working before, anyway maybe it wasn't at least it's now tested.

That's exactly what I did here $identifiers[$propertyName] = $this->getIdentifiersFromItem($identifiers[$propertyName]);, or you had an easier solution in mind?

@teohhanhui
Copy link
Contributor

Your current method allows for recursion of more than 1 level. I'm not sure how we're going to actually make that work... For the case of related entity used as an identifier, we can only allow non-composite identifier which is not a relation.

@soyuka
Copy link
Member Author

soyuka commented May 26, 2016

I can try to remove recursion, I like recursion too much I think 😜.

For the case of related entity used as an identifier, we can only allow non-composite identifier which is not a relation.

Sorry I didn't understood. Isn't this enough? It lets the user choose if the identifier should be serialized or not, according to normalization groups.


Recursion removed, thx @teohhanhui it's better now.

@soyuka soyuka force-pushed the bug-reproduction-identifiers branch from d387d91 to 1e22702 Compare May 26, 2016 08:45
@teohhanhui
Copy link
Contributor

teohhanhui commented May 26, 2016

It lets the user choose if the identifier should be serialized or not, according to normalization groups.

It has nothing to do with serialization. We're talking about the URL here...

@soyuka
Copy link
Member Author

soyuka commented May 26, 2016

Sorry, though you were talking about the second commit. I rewrote 3bf5323, should be better now.

@Simperfit
Copy link
Contributor

👍

@soyuka
Copy link
Member Author

soyuka commented May 30, 2016

ping @api-platform/core lgtm

}
}

if (0 === count($identifiers[$propertyName])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer empty (for performance).

@soyuka soyuka force-pushed the bug-reproduction-identifiers branch from 1e22702 to 69fe23d Compare June 1, 2016 07:53
@soyuka soyuka force-pushed the bug-reproduction-identifiers branch from 69fe23d to 96fd131 Compare June 1, 2016 07:56
@soyuka
Copy link
Member Author

soyuka commented Jun 1, 2016

I can squash my commits but I think they are best separated, let me know.

@dunglas dunglas merged commit 8bdf829 into api-platform:master Jun 2, 2016
@dunglas
Copy link
Member

dunglas commented Jun 2, 2016

Thanks @soyuka!

@soyuka soyuka deleted the bug-reproduction-identifiers branch June 7, 2016 17:56
magarzon pushed a commit to magarzon/core that referenced this pull request Feb 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants