If I had a model that had relationship (1-m)... is...
# orm-help
c
If I had a model that had relationship (1-m)... is there a way to query count of M and if I am one of those? I guess what is the most efficient way to deal with the following problem? I have a
Post
that has relationship to many
Likes
- When retrieving many posts... what is the most efficient way to see how many likes its got and if you are on of those likes. Seems like you would need several queries? Does anyone have an example of the most performant way to do this?
👀 1
@Daniel Norman Seems similar to what you did in your load test this morning!
👌 1
@Luca maybe you have some recommendations?
🤷‍♂️ 1
r
@Chase Roossin 👋 Unfortunately it’s not directly possible to get the count of the relations at the moment. As a workaround, you would need to fetch the relation in this case and return the
length
of the items fetched. There’s an open request here for the same so it would be great if you could add a 👍 so that we can look into the priority for this.
👍 1
c
@Ryan I went ahead and gave a thumbs up! So in theory, you’d recommend getting the array of posts (including its likes) then iterating through each post, and checking the length of likes and if your user was in that array of likes?
r
So in theory, you’d recommend getting the array of posts (including its likes) then iterating through each post, and checking the length of likes and if your user was in that array of likes?
This would be different then just getting the count of likes as you would need to likes to fetch the users.