-
I want to perform an embedded filter that will only return the top-level records matching the embedded filter- that works fine. In this example, only one embedded phone number is returned, but I would like to see all 3 for the top-level record. curl 'http://127.0.0.1:8432/stores?select=name,'\
'Phones:phones!inner(id,store_id,phone_number)'\
'&phones.phone_number=eq.111-111-1111'
[{"name":"Store 1","Phones":[{"id":1,"store_id":1,"phone_number":"111-111-1111"}]}]% create table public.stores
(
id bigserial constraint stores_pk primary key,
name varchar
);
create table public.phones
(
id bigserial constraint phones_pk primary key,
phone_number varchar,
store_id bigint
constraint phones_store_id_fk references public.stores
);
INSERT INTO public.stores (id, name)
VALUES (1, 'Store 1');
INSERT INTO public.stores (id, name)
VALUES (2, 'Store 2');
INSERT INTO public.phones (id, phone_number, store_id)
VALUES (1, '111-111-1111', 1);
INSERT INTO public.phones (id, phone_number, store_id)
VALUES (2, '111-111-1112', 1);
INSERT INTO public.phones (id, phone_number, store_id)
VALUES (3, '111-111-1113', 1);
INSERT INTO public.phones (id, phone_number, store_id)
VALUES (4, '222-222-2221', 2);
INSERT INTO public.phones (id, phone_number, store_id)
VALUES (5, '222-222-2222', 2);
INSERT INTO public.phones (id, phone_number, store_id)
VALUES (6, '222-222-2223', 2); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I had to do the same thing multiple times now, and the only thing that worked was embedding twice - once for filtering and once for the actual response. Not pretty, but it works: GET /stores?select=name,Phones:phones(id,store_id,phone_number)&filtered_phones:phones!inner(phone_number)&filtered_phones.phone_number=eq.111-111-1111 |
Beta Was this translation helpful? Give feedback.
-
Just needed a minor tweak, thanks! curl 'http://127.0.0.1:8432/stores?select=name,Phones:phones(id,store_id,phone_number),filtered_phones:phones!inner(phone_number)&filtered_phones.phone_number=eq.111-111-1111'
[{"name":"Store 1","filtered_phones":[{"phone_number":"111-111-1111"}],"Phones":[{"id":1,"store_id":1,"phone_number":"111-111-1111"},
{"id":2,"store_id":1,"phone_number":"111-111-1112"},
{"id":3,"store_id":1,"phone_number":"111-111-1113"}]}] |
Beta Was this translation helpful? Give feedback.
Just needed a minor tweak, thanks!