Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in parseHasMany relationship #227

Open
Xubair-Dev opened this issue Jun 18, 2019 · 1 comment
Open

Issue in parseHasMany relationship #227

Xubair-Dev opened this issue Jun 18, 2019 · 1 comment

Comments

@Xubair-Dev
Copy link

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

@safo6m
Copy link
Collaborator

safo6m commented Jul 18, 2019

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants