Question: Can joins be resolved based within groups based on first table ?
tcarac opened this issue · 1 comments
tcarac commented
Hi, first of all thanks for this, it looks amazing.
Our use case is trying to resolve a specific subset of data resolving fk within groups so what I'm looking for is to do:
# .pgsync.yml
groups:
users:
users: "where created_at > '2024-01-01'
company_users: "where user_id = $users.id"
companies: "where company.id = $company_users.company_id"
Being queries in groups sequential is this possible ?
ankane commented
Hi @tcarac, you'd need to do something like:
groups:
users:
users: "where created_at > '2024-01-01'"
company_users: "where user_id IN (select id from users where created_at > '2024-01-01')"
companies: "where id IN (select company_id from company_users inner join users ON company_users.user_id = users.id WHERE users.created_at > '2024-01-01')")
You could also make the date a variable to avoid repeating it.