Skip to content

Collection of embedded resources are not supported #1

@intellix

Description

@intellix

In your list of examples, you specify that it's possible to do something like: books.query() but am not seeing the support if you return an actual collection of embedded entities:

The following test fails with Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object:

describe('collections:', function() {

    var Book;
    beforeEach(function() {
      Book = hResource('book', '/books/:id', {id: '@id'});
    });

    it('returns an array of entities embedded within a collection', function() {

      var response = {
          _embedded: {
              books: [
                  {
                      id: 1,
                      title: 'The BFG'
                  },
                  {
                      id: 2,
                      title: 'Matilda'
                  },
                  {
                      id: 3,
                      title: 'James and the Giant Peach'
                  },
              ]
          },
          _links: {
              self: {
                  href: '/books'
              }
          },
          count: 3,
          total: 10
      };
      $httpBackend.expectGET('/books').respond(200, response);

      var books = Book.query();

      $httpBackend.flush();
      expect(books).toBeArray();

    });

  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions