dimanche 17 avril 2016

Ember model relationship not matching API

I have two models who looks like this:

// models/database.js
export default DS.Model.extend({
   title: DS.attr(),
   /*...*/
   documents: DS.hasMany('document')
});

// models/document.js
export default DS.model.extend({
   name: DS.attr(),
   /*...*/
   database: DS.belongsTo('database')
});

Is also have some routes

Router.map(function() {
  this.route('databases', function() {
    this.route('database', {
      path: ":database_id"
    }, function() {
      this.route('documents');
    });
  });
});

When I call /database//documents if got nothing.

I think the problem is I'm working with an JSON HAl API and when I ask for databases on API I receive this kind of response.

{
"_embedded": {
    "databases": [
        {
            "_links": {
                "self": {
                    "href": "<API_URL>/databases/7ec39267b544424c/",
                    "reference": "7ec39267b544424c",
                    "title": "00000006"
                }
            },
            "database": {
                "name": "00000006",
                "reference": "7ec39267b544424c",
                "title": "****"
            }
        },
        {
            "_links": {
                "self": {
                    "href": "<API_URL>/databases/aace19af004144a4/",
                    "reference": "aace19af004144a4",
                    "title": "00000007"
                }
            },
            "database": {
                "name": "00000007",
                "reference": "aace19af004144a4",
                "title": "******"
            }
        }
    }]
}

As you can see there no documents attributs on JSON returned. If I want databases documents I've to call "/databases//domains//documents"

There's still a way to link documents to a database by specifying that the documents are recoverable at this URL (/databases//domains//Documents")?




Aucun commentaire:

Enregistrer un commentaire