reyesoft / ngx-jsonapi

JSON API client library for Angular 5+ 👌 :: Production Ready 🚀
https://ngx-jsonapi.reyesoft.com/
MIT License
101 stars 52 forks source link

Inserting data includes in relationship failed #159

Closed Anngeluss closed 5 years ago

Anngeluss commented 5 years ago

According to the Jsonapi standard, it is possible to have the following structure :

relationships: {
  author : { data : { id: "1", type: "people" } }
},
"included": [{
    "type": "people",
    "id": "9",
    "attributes": {
      "firstName": "Dan",
      "lastName": "Gebhardt",
      "twitter": "dgeb"
    },
    "links": {
      "self": "http://example.com/people/9"
    }
  }
]

For trying, relationships are not filled at the property "data" because aggregation of data is done on type recognition in relationships. In the example above, he looks for relationship ["people"] But the type should be search within the relationships relationship["author].data.type === "people"

NB: please excuse my English mistakes.

pablorsk commented 5 years ago

Hi @Anngeluss ,

habatmu-birhanu commented 5 years ago

Hi @Anngeluss ,

  • can you reference to that specification point?
  • can you put al full POST example? (you just put a relationship)

Hi Pablo How can disable cache support I also used the following configuration in in my App Module but still cache is working any help will be appreciated NgxJsonapiModule.forRoot({ url: 'http://localhost:3000/', cache_prerequests: false, cachestore_support: false })

Anngeluss commented 5 years ago

Hello @pablorsk,

  • can you reference to that specification point?

Members of the relationships object (“relationships”) represent references from the resource object in which it’s defined to other resource objects : https://jsonapi.org/format/#document-resource-object-relationships

So the name of the relationship can be different from the type of the resource since it is defined according to its context. If I request articles, I need a "author" relationship that is of "people" type

  • can you put al full POST example? (you just put a relationship)

The example is directly on the standard json api : https://jsonapi.org/

Thank you

maxi7587 commented 5 years ago

Hi @Anngeluss ! Following with this example, you can use a different relationship name by adding the corresponding relationship in the Article resource and typing it as a People document collection (to take advantage of typescript):

export class Article {
    public attibutes = {
        title: ' '
    }

    public relationships = {
        authors: new DocumentCollection<People>()
    }
}

This way, the library will use the relationship alias authors to display a collection of resources of type people. You can access this collection at article.relationships.authors.data.

Remember that PeopleService must be registered before making a request to the API (in case that you are using lazy loaded modules).

maxi7587 commented 5 years ago

Sorry... I've just realized that it fails when saving... working on it!

maxi7587 commented 5 years ago

Solved in #171