angular2-jsonapi icon indicating copy to clipboard operation
angular2-jsonapi copied to clipboard

Accessing metadata on single records

Open therealcljohn opened this issue 6 years ago • 2 comments

Hi @RooTooZ,

Edit: I added a merge request down below because I could not find how to achieve what I need overnight.

I'm refering to GH-64. This pull request adds access to metadata and it works quite well for collections. But how can I access the metadata of a single record?

I tried the following code but it does not seem to work. The documentation has an example only for the findAll-method so I'm quite unsure if accessing meta of single records is currently possible.

Querying:

            this.datastoreService.findRecord<Role>(Role, id, {
                include: 'permissions,users'
            }).subscribe(
                (role: Role) => {
                    console.log(role.meta);
                    console.log(role.getMeta());
                    this.role = role;
                },
                (errorResponse) => {
                    this.locationService.back();
                }
            );

Role model

@JsonApiModelConfig({
    type: 'roles',
    meta: JsonApiMetaModel
})
export class Role extends JsonApiModel {
    @Attribute()
    name: string;
    @Attribute()
    description: string;

    @HasMany()
    users: User[];
    @HasMany()
    permissions: Permission[];
}

Can you clarify this for me?

Best regards Clemens

therealcljohn avatar Feb 17 '18 23:02 therealcljohn

I added a merge request which will allow accessing metadata when retrieving single resources.

There is one challenge left: accessing medatata of models when they have been fetched as part of a collection using findAll. Accessing the documents medata works fine using document.getMeta(). But each model inside document.getModels() can also have metadata attached which we can not access at the moment. I thing we need something like model.getMeta() but for this we need to put metadata into the datastorage.

In #26 we had a proposal on how to achieve this which would have resulted in storing metadata inside the datastorage as far as I can remember. Maybe one day we can catch this up without too many breaking changes.

Ideas welcome :)

therealcljohn avatar Feb 18 '18 11:02 therealcljohn

Guys can you also do an example for this in the docu? Would be nice as hidden feature are hard to find.

Mojo1 avatar Feb 25 '18 11:02 Mojo1