Replies: 3 comments 2 replies
-
One possible direction could be something like this: const all_saved = computed(() =>
saved
.query()
.with("saved_item", (saved_item) =>
saved_item
.whereHas("movie", (query) => query.with("artists"))
.orWhereHas("episode", (query) => query.with("episode"))
)
.get()
); Where you specify the relationships based on having certain other relationships. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Another solution could be to make fake relationships on other models. Like giving my episodes an artist relationship which will never have anything. But this does not seem very scalable. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Just pining so you see this. @CodeDredd |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I have now arrived at the point in my pinia orm journey that I need to start using polymorphic relationships. Things so far have been good. Besides the
.with
.I have a schema like this:
The first issue I encountered is that all my HumanSavedX models had different primary keys. This does not work with polymorphic relationships because you can only specify one custom ownerKey. I could work around this by specifying the
saved_id
getter onHumanSavedMovie
andHumanSavedEpisode
. Maybe being able to pass a list of ownerKeys the same length as the first input to MorphTo is a good idea.However, this trick does not work for relationships. This query does not work:
This one gives the error that the
movie
relationship does not exist onHumanSavedEpisode
.and neither this query works:
This one gives the error that the
episode
relationship does not exist onHumanSavedMovie
.One solution of course would be to rename movie and episode to
item
.I could still use the composite primary key but it would be less clear. Also, this just moves the problem. My
movie
model happens to have anartists
relationship. This relationship does not exist on episodes. This means I can not query the artists on the movie!This error means that, yes you can link multiple entities to the same entity with polymorphic relationships. The relationships of the entities that you link to have to be quite similar for it to be useful.
Could we think about a way to not throw an error with polymorphic relationships and queries like this?
I would like to have a discussion about this.
Beta Was this translation helpful? Give feedback.
All reactions