-
Notifications
You must be signed in to change notification settings - Fork 122
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
Support mixed types in HasMany relationship #215
Comments
I think solution 1 would also solve a problem, that would occur if we use polymorphic relationships as mentions in issue #201 |
Regarding solution 2: To realize this, TypeScript needs to expose the array element type (see microsoft/TypeScript#7169, e.g. |
Correct, the solution 2 is technically the correct one, but for now we can go with the solution 1 due to its simplicity. |
Closing because #216 was merged. |
A
HasMany
relationship (e.g.books: Book[]
) does not allow mixed types (e.g.CrimeBook
,NovelBook
), even if they extend the same expectedHasMany
type (Book
).Problem
In this line, the type of the first element in the relationship is checked against all other types.
angular2-jsonapi/src/services/json-api-datastore.service.ts
Line 249 in a736c0f
Example
I have
and the models
Possible solution 1
Collect
modelEndpointUrl
ortype
of all relationship items and check if there is only one unique. This way, even if thetype
of the items differ (crimeBooks
ornovelBooks
), if themodelEndpointUrl
is the same (books
), all should be fine.Possible solution 2
Check, if all relationship items are instances of the model, that the
HasMany
attribute expects (Book
).I will create a pull request for solution 1, but I am not sure if solution 2 would be more clean (Although only
type
andmodelEndpointUrl
are relevant, when talking to the server, and not the Typescript type of theHasMany
attribute).The text was updated successfully, but these errors were encountered: