Skip to content

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented May 24, 2016

Q A
Bug fix? yes
New feature? nope
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets
License MIT
Doc PR

I added a behat test to reproduce an issue, for easy debugging use ./vendor/bin/behat -vv --stop-on-failure --name 'Relations support' and rm -rf tests/Fixtures/app/cache/* to clear the database before a second call.

I set up a handmade ManyToMany relation, where the association table is entity-represented so that additional fields could be added to the relation (RelatedToDummyFriend).
RelatedDummy has a new OneToMany relation to this association entity (RelatedToDummyFriend). RelatedToDummyFriend references DummyFriend on a ManyToOne basis.

Here's the error:

Warning: rawurlencode() expects parameter 1 to be string, object given in ~/forks/api-platform/src/Bridge/Symfony/Routing/IriConverter.php line 94

Ref: https://github.com/api-platform/core/blob/master/src/Bridge/Symfony/Routing/IriConverter.php#L94 gets the full object instead of the id.

This was working before #533, and this test will avoid future regression.

@Simperfit: as you worked on this, do you see where it could come from/any idea of a fix? Thanks!

@soyuka soyuka force-pushed the bug-reproduction-identifiers branch from b7d3a3f to 58fa01a Compare May 24, 2016 16:25
@Simperfit
Copy link
Contributor

Simperfit commented May 24, 2016

I've check that and when I debug this part of the function :

It returns :

Scenario: Create a friend relationship                                   # features/relation.feature:70
    When I send a "POST" request to "/related_to_dummy_friends" with body: # Sanpi\Behatch\Context\RestContext::iSendARequestToWithBody()
      """
      {
          "name": "Friends relation",
          "dummyFriend": "/dummy_friends/1",
          "relatedDummy": "/related_dummies/1"
      }
      """
      │ bool(true)
     │ object(stdClass)#5381 (5) {
      │   ["__CLASS__"]=>
      │   string(61) "ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyFriend"
      │   ["__IS_PROXY__"]=>
      │   bool(true)
      │   ["__PROXY_INITIALIZED__"]=>
      │   bool(false)
      │   ["id"]=>
      │   string(1) "1"
      │   ["name"]=>
      │   NULL
      │ }
      │
    Then the response status code should be 201                            # Behat\MinkExtension\Context\MinkContext::assertResponseStatus()
      Current response status code is 500, but 201 expected.

Which means that Doctrine did not hydrate this value.

I think that we should check if it's a proxy class and get the id.

@soyuka soyuka force-pushed the bug-reproduction-identifiers branch from 58fa01a to 8786569 Compare May 25, 2016 08:45

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?

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.

2 participants