RLS Policy With Join

Trying to follow along the docs with how to create an RLS policy with joins but cant seem to figure it out. I have cart_items which have a product_id and an account_id. the Products table also has an account_id.

I am trying to create an RLS policy on insert so that you cannot add your own products to your cart but this doesn't seem to work. What am I missing :mind_blow_astonished: . Appreciate the help!

create policy "Cart items cannot be added for cart account's products"
  ON public.cart_items for INSERT
  to authenticated
  WITH CHECK (
    not exists (
      select 1 from products
      where products.account_id = account_id
    )
  );
Was this page helpful?