-
Notifications
You must be signed in to change notification settings - Fork 122
Support for multiple types per HasMany field #108
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
Conversation
|
I had the same issue, and this fixed the problem for me. Thanks @abrararshad! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, only minor things remaining.
| if (relationshipModel.length > 0) { | ||
| this[metadata.propertyName] = relationshipModel; | ||
| let allModels: any = []; | ||
| let modelTypesFetched: any = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you avoid any, this should be string[].
src/models/json-api.model.ts
Outdated
| let modelType: ModelType<this> = Reflect.getMetadata('JsonApiDatastoreConfig', this._datastore.constructor).models[typeName]; | ||
| if (modelType) { | ||
| let relationshipModel: JsonApiModel[] = this.getHasManyRelationship(modelType, relationship.data, included, typeName, level); | ||
| if (relationshipModel.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you define allModels als var and write this as allModels = allModels.concat(relationshipModels)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to relationshipModels.
|
Travis is throwing error at "Failed at the angular2-jsonapi@3.7.1 prepublish script 'ngc'." Well I have ran all scripts locally build, tests, prepublish, they are all good. I will try to push again to see if it passes |
|
I was viewing the logs through a small window and could not notice this error on Travic before "Could not find a declaration file for module 'date-fns/format'" I added @types/date-fns into dev even though its readme says its not needed |
|
Just confirming. I even changed the code back to the commit when the test was successfully passed. I think it needs more eyes on this probably. |
|
Rebased the commits. Tests passed locally |
|
Hi @ghidoz can you please update latest code. It will be very helpful for our project. Thanks |
|
Nice work, just one issue for me. If you have: You will loose the order A -> B -> A -> B. The output is A -> A -> B -> B UPDATE: I fixed this issue on a fork: |
Currently, we only get one type of models per HasMany field but if there are more than one type they are not being checked.
For example
-- entity:
----relationships:
--------components:
------------Type: A
------------Type: B
Whichever comes first in relationships array gets loaded by the library (in this case Type:A), not the second type (in this case Type:B)
Another loop is added in parseHasMany function of json-api.model.ts. And it also tracks typeName not to loop over again by the same type in order to avoid duplicate entries.