I have a purchases table which connects users to d...
# sql
m
I have a purchases table which connects users to digital products they've purchased. How do I get RLS set up so that only users who have purchased a product can view the product info? Somewhat programmatically,
view product_info if purchases has row with product.id and user.id
. Hope that makes sense.
n
Do you have a user_id column on that table? If so you can do something like user_id=uid()
m
Well there are 4 tables. Users, purchases, products, and product_info. I want the user to only have access to the rows in product_info for the products they have purchased.
User_id is only a FK in the purchases table
n
Anything that returns true can be used as policy'
So you could do something like SELECT count(something) FROM product_info JOIN purchases ON purchases.product_info_id = product_info.product_info_id WHERE purchases.user_id = uid() >=1