tuyakhov / yii2-json-api

Implementation of JSON API specification for the Yii framework
142 stars 18 forks source link

Update readme about relationships #30

Open yairpe opened 7 years ago

yairpe commented 7 years ago

In general, it is not clear what parts of jsonapi standard is covered by the extension and what is left for the implementor or maybe will be included in future updates of the extension.

There are two areas in specific that are not covered by the readme:

  1. resources and sub-resources

For example, the readme says nothing that it uses eaxtraFields() in the parent model to allow the use of ?include=child. I had to extract it from the sources. i.e in Countries.php

    public function extraFields()
    {
        return ['cities']
    }
    public function getCities()
    {
        return $this->hasMany(Cities::className(), ['country_id' => 'id']);
    }

and in Cities.php

    public function getLinks()
    {
        return [
            Url::home(true) . 'v1/cities/' . $this->id,
        ];
    }

to be able to use something like v1/countries/10?include=cities

  1. Relationships It is not clear how they work and how to use them. What is covered? just serializing the output? or more than that since the source have UpdateRelationshipAction.php?

In short, some more info with usage examples would be much welcomed

tuyakhov commented 7 years ago
  1. Almost everything from jsonapi standard is covered in this extension, except for filtering and sorting. Mostly because JSON API is agnostic about the strategies supported by a server. It only requires using the filter, sort query parameters for filtering/sorting operations. But despite that, I am currently working on those 2 parts, in order to provide support of some basic operations.
  2. Apart from serializing the output, updating relationships are supported as well. And it works as described in specification so that you can modify relationships along with resources (http://jsonapi.org/format/#crud-updating-resource-relationships) or by hitting the independent URL (http://jsonapi.org/format/#crud-updating-relationships) in this case you have to use UpdateRelationshipAction.php
mtangoo commented 7 years ago

I was thinking about forking ember's rental store and make Yii2 API as BE. unfortunately I don't have any time in hand currently. But someone can pick that and make it a reality. It will serve as good example

https://github.com/ember-learn/super-rentals

yairpe commented 7 years ago

Almost everything from jsonapi standard is covered in this extension, except for filtering and sorting. Mostly because JSON API is agnostic about the strategies supported by a server. It only requires using the filter, sort query parameters for filtering/sorting operations. But despite that, I am currently working on those 2 parts, in order to provide support of some basic operations.

Great, waiting for it. It's much better to have it as part of the extension rather than individual implementations in several places.

Thank you Anton