Skip to content

Issue in parseHasMany relationship #227

Open

Description

@Xubair-Dev

Hi Team,

I am getting below error
parseHasMany - Model type for relationship activities not found

Please go through below codes

ParentActivity.ts
import { JsonApiModel, JsonApiModelConfig, Attribute, HasMany } from "angular2-jsonapi";
import { ChildActivity } from "./childactivity.model";
@JsonApiModelConfig({
type: 'parent-activity'
})
export class ParentActivity extends JsonApiModel {
@Attribute()
id:string;
@Attribute()
name:string;
@hasmany()
activities: ChildActivity[];
}

ChildActivity.ts
import { JsonApiModel, JsonApiModelConfig, Attribute, BelongsTo } from "angular2-jsonapi";
@JsonApiModelConfig({
type: 'child-activity'
})
export class ChildActivity extends JsonApiModel {

@Attribute()
id:string;
@Attribute()
name:string;
@Attribute()
description: string;

}

@Injectable()
@JsonApiDatastoreConfig()
export class ActivityDataStore extends JsonApiDatastore {

constructor(http: HttpClient, @Inject('API_URL') public linkToAPI: string) {
super(http);
this.config = {
baseUrl: this.linkToAPI,
models: {
activities: ChildActivity,
activityGroup: ParentActivity
}
}
}
}

Now in analysis I found issue in below lines
json-api.model.js -> JsonApiModel.prototype.parseHasMany ->
var modelType = Reflect.getMetadata('JsonApiDatastoreConfig', this.internalDatastore.constructor).models[typeName];

here typeName is child-activity which coming as undefined because in models array it is activities and its looking for child-activity.
The key activities referring from JsonApiDatastore models array and typeName 'child-activity' getting value from ChildActivity class type metadata.

I hope you understand the Issue and root cause.

Please share if you have any work-around or how can I override this function if possible.

Thanks

Activity

  1. safo6m commented on Jul 18, 2019

    @safo6m
    Collaborator

    This should be fixed in version v7.1.0
    @Xubair-Dev can you please verify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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