Open Zyles opened 1 month ago
Read policy works correctly:
create policy "Can only read group rows"
on "public"."cities"
to authenticated
using (
user_is_group_member(group_id)
);
provide the group ID
Hmm okay. I was hoping for a better automated solution.
If you forget to pass the group_id for example in code.
Just like the user_id is autopopulated with auth.uid()
You could add a before trigger that could maybe do something like this but the only way for it to know which group_id to use in the absence of one would be in the case of an update rather than an insert. Are you trying to update or upsert/insert? If it's an update, set a trigger to carry the group_id value of the old record over to the new one. Other than that, you logically must include the group_id in the submitted data so that the db knows what group the incoming data belongs to.
Can you provide CRUD example policies for a custom table?
I saw the examples for group tables and tried to apply them but am running into the following problem:
I have a cities table:
Foreign key group_id to groups.id
And policy:
I also tried this policy:
Error:
JS code: