Skip to content

Relationships only included when corresponding service is constructedΒ #338

@TimmayNL

Description

@TimmayNL

When I use a Service to get a Resource and use include to also fetch data for relationships, I need to construct the Service for the included Resource(s) for it to work.

Taking the demo as example:

   public constructor(private booksService: BooksService) {
        booksService
            .all({
                include: ['author']
            }).subscribe(books => {
            console.log(books);
        })
    }

will return a DocumentCollection with all books, where every Book has an author relationship. But when you look at the data in this author Resource, it is empty. It does have the correct id, but attributes is a completly empty object.

Only when I also inject the AuthorsService, the attributes for the included author are loaded.

   public constructor(private booksService: BooksService, private authorService: AuthorsService) {
        booksService
            .all({
                include: ['author']
            }).subscribe(books => {
            console.log(books);
        })
    }

I am not using the AuthorService anywhere, just injecting it and thus constructing it is enough.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions