-
-
Notifications
You must be signed in to change notification settings - Fork 78
Non-existent one-to-one relationships #94
Comments
I will note, some other things I tried:
|
Thanks for the detailed report.
public function emptyToOne($device)
{
return new Relationship(new EmptyResource);
}
public function emptyToMany($device)
{
return new Relationship(new EmptyCollection);
}
Scratch that! I found an easier way: simply returning null as the resource identifier if the data is null. So it'll look like this: public function emptyToOne($device)
{
return new Relationship(new Resource(null, new Serializer));
}
public function emptyToMany($device)
{
return new Relationship(new Collection([], new Serializer));
} |
Since the natural thing to do is: return new Relationship(new Resource($data, new Serializer)); where $data may or may not be null. Now if $data is null, the resource identifier will be returned as null too, indicating an empty relationship.
👍 This works great, thank you! |
Agreed - It worked exactly like expected. Will there be a new version of tobscure/json-api released soon? |
Hi there,
I'm taking a look at this part of the spec on relationships.
I'm not sure if my understanding is incorrect or not. My URL looks like this:
GET /v1/devices?include=group
I have done this to get the "relationships" key to show up for all items:
Originally I tried to return null instead of a
Relationship
, but that removes the "relationships" block entirely. The only problem with the above solution is that it seems to only support "X-to-many" relationships. In other words, the response from the API looks like this:I believe that in reality, I want it to look like this:
Is there any way to get this result? Thank you so much for this library! It's very flexible and useful.
The text was updated successfully, but these errors were encountered: