Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceIdentifier does not consider "data" key #16

Closed
qpautrat opened this issue Feb 24, 2016 · 5 comments
Closed

ResourceIdentifier does not consider "data" key #16

qpautrat opened this issue Feb 24, 2016 · 5 comments
Labels

Comments

@qpautrat
Copy link
Contributor

Hi there,

As JSON API specification says

If a relationship is provided in the relationships member of the resource object, its value MUST be a relationship object with a data member.

Correct me if i'm wrong, but ResourceIdentifier does not care about this data key.
And as we pass complete array in Request it results as null.

You can try it with this simple example from JSON API documentation:

{
  "data": {
    "type": "photos",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "relationships": {
      "photographer": {
        "data": { "type": "people", "id": "9" }
      }
    }
  }
}
@christophehurpeau
Copy link

👍

@dimvic
Copy link
Contributor

dimvic commented Feb 24, 2016

This type of query is exactly what's supported by the implementation though, ResourceIdentifier is what encapsulates the data for each relationship object, for example:

//query
{
  "data": {
    "type": "photos",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "relationships": {
      "photographer": {
        "data": { "type": "people", "id": "9" }
      },
      "others": {
        "data": [
          { "type": "other", "id": "1" },
          { "type": "other", "id": "2" }
        ]
      }
    }
  }
}
//ToOneRelationship hydrator
function($domainObject, $relationship, $data, $relationshipName) {
    $resourceIdentifier = $relationship->getResourceIdentifier();
    //$resourceIdentifier->getType() is "people"
    //$resourceIdentifier->getId() is "9"
    ...
}

//ToManyRelationship hydrator
function($domainObject, $relationship, $data, $relationshipName) {
    foreach ($relationship->getResourceIdentifiers() as $resourceIdentifier) {
        //$resourceIdentifier->getType() is "other"
        //$resourceIdentifier->getId() is "1", then "2"
        ...
    }
    ...
}

@qpautrat
Copy link
Contributor Author

I don't get it @dimvic .

$jsonApi->getRequest()->getResourceToOneRelationship('photographer') returns null and it should not.

@kocsismate
Copy link
Member

My fear is that $request->getResourceToOneRelationship() does not return any value. I have already fixed some similar issues in the past, but sometimes I just forget about the return statement. :D

Anyway, thanks for catching this problem! I can fix it right now, but can only assure if it really works in the evening.

@kocsismate
Copy link
Member

I found another bug with the aformentioned method, so I fixed it. Feel free to reopen the issue if you find it otherwise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants