-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Polymorphic relationships with unknown model types #4377
Comments
Thanks for opening this issue @Turbo87! |
@pangratz I just want to add my 2c since this has bitten me before. Particularly in the area where I may want to have any number of "targets" or "actors" for an app's feed model. Mongoose uses type keys and they work surprisingly well. I feel the declaration is fairly dry too. |
I suspect we can resolve this by eliminating the assertion in |
This issue follows the discussion with @pangratz on Slack regarding the use of a polymorphic
belongsTo
relationship with model types that might not be known to the app.My use case is roughly like this:
From the API I'm getting multiple
object
objects, each with atype
property describing the type of object. Unfortunately the list of types is not fixed and new types can be added by the API authors at any time. Currently a new type will cause an "Unknown model" exception though.One possible solution to this is checking for the existence of the related model factory in the
object
serializer and settingrelated
tonull
if the model can't be found. The only ways to check if a model factory exists right now are a try-catch aroundmodelFor()
or manually checking the container formodel:...
. It might be a good idea to expose some public method for this use case instead.Another use case of this is running
peekRecord()
with a type parameter coming from a WebSocket event. In this case I have to handle a missing record viaif
but then also handle the missing model type by wrapping it in a try-catch./cc @pangratz
The text was updated successfully, but these errors were encountered: