How to add relations to a View collection. #2029
-
I have a view collection, and I want it so that I can query the amount of members and posts within a SELECT
communities.id,
count(DISTINCT posts.id) as posts,
count(DISTINCT users.id) as members
FROM communities
LEFT JOIN users on users.communities LIKE '%' || communities.id || '%'
LEFT JOIN posts on posts.community = communities.id
GROUP BY communities.id This works, but it only has an id- it's not a relation, meaning I can't indirect expand. How do I make it so that there's a column |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 13 replies
-
You can add the column As a workaround, for now you can try specifying a dummy primary table: SELECT
communities.id,
communities.id as community,
count(DISTINCT posts.id) as posts,
count(DISTINCT users.id) as members
FROM (select 1) as dummy, communities
LEFT JOIN users on users.communities LIKE '%' || communities.id || '%'
LEFT JOIN posts on posts.community = communities.id
GROUP BY communities.id |
Beta Was this translation helpful? Give feedback.
-
This little post helped me so here is my code for others to use: (It's just to count how many times a certain id is used in another table) |
Beta Was this translation helpful? Give feedback.
-
Hi, I have some issues too finding a way to add a relation to a view collection. This is a simplified use case. I have a collection that has three fields:
These are some example records:
Now what I want to achieve is to have a view collection that for each store provides an array with unique inventory items.
The problem is that the store column has no relation with the stores table I even tried referencing an id column like this but with no luck...
How can this be achieved? |
Beta Was this translation helpful? Give feedback.
-
i have a |
Beta Was this translation helpful? Give feedback.
-
thank you very much, much appreciated. thanks. works perfectly. |
Beta Was this translation helpful? Give feedback.
You can add the column
communities.id as community
but in order to be detected asrelation
it needs to be from "non-primary" table (I'll consider updating the rules and allow any aliased id column to be detected asrelation
).As a workaround, for now you can try specifying a dummy primary table: