Skip to content

Fetch related objects #12

@generalov

Description

@generalov

The HyperlinkedModelSerializer produces urls for related objects like that:

{
    url: "http://localhost:8000/orders/1/"
    cargo: "http://localhost:8000/cargo/1/"
}

Therefore a REST client needs no prior knowledge about url schema. But code for the navigation some annoying:

var Order = djResource('/orders/:order_id', {order_id: '@id'});
var orders = Order.query();
orders.$then(function(response) {
    angular.forEach(response.data, function(order) {
        var cargoUrl = order.cargo;

        // prevets port stripping from url
        // see https://github.com/angular/angular.js/issues/1243
        cargoUrl = cargoUrl.replace(/(:\d)/, '\\$1'); 

        order.cargo = djResource(cargoUrl).query();
    }
});
$scope.orders = orders;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions