-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
split queries for embedded resources when using alias #821
Comments
seems like you have two fk columns pointing to the same table. |
Not related to #918. The issue here is that aliased embeds cannot be used aliased in filters. create table test.space(
id integer primary key,
name text
);
create table test.zone(
id integer primary key,
name text,
zone_type_id integer,
space_id integer references test.space(id)
);
insert into test.space values (1, 'space 1');
insert into test.zone values (1, 'zone 1', 2, 1), (2, 'zone 2', 2, 1), (3, 'store 3', 3, 1), (4, 'store 4', 3, 1); The wanted response is: {
"id":1,
"name":"space 1",
"zones":[
{
"id":1,
"name":"zone 1",
"zone_type_id":2
},
{
"id":2,
"name":"zone 2",
"zone_type_id":2
}
],
"stores":[
{
"id":3,
"name":"store 3",
"zone_type_id":3
},
{
"id":4,
"name":"store 4",
"zone_type_id":3
}
]
}
] Reproducing the errors:
GET /space?select=id,name,zones:zone(id,name,zone_type_id),stores:zone(id,name,zone_type_id)
&zone.zone_type_id=eq.2
&zone.zone_type_id=eq.3 [
{
"id":1,
"name":"space 1",
"zones":[],
"stores":[
{
"id":1,
"name":"zone 1",
"zone_type_id":2
},
{
"id":2,
"name":"zone 2",
"zone_type_id":2
},
{
"id":3,
"name":"store 3",
"zone_type_id":3
},
{
"id":4,
"name":"store 4",
"zone_type_id":3
}
]
}
] The problem here is that the filters are applied to only the first embed.
GET /space?select=id,name,zones:zone(id,name,zone_type_id),stores:zone(id,name,zone_type_id)
&zones.zone_type_id=eq.2
&stores.zone_type_id=eq.3 [
{
"id":1,
"name":"space 1",
"zones":[
{
"id":1,
"name":"zone 1",
"zone_type_id":2
},
{
"id":2,
"name":"zone 2",
"zone_type_id":2
},
{
"id":3,
"name":"store 3",
"zone_type_id":3
},
{
"id":4,
"name":"store 4",
"zone_type_id":3
}
],
"stores":[
{
"id":1,
"name":"zone 1",
"zone_type_id":2
},
{
"id":2,
"name":"zone 2",
"zone_type_id":2
},
{
"id":3,
"name":"store 3",
"zone_type_id":3
},
{
"id":4,
"name":"store 4",
"zone_type_id":3
}
]
}
] The problem here is that the aliased filters( |
Example :
if you select with alias (zones:zone and stores:zone) and filter without (space.zone.zone_type_id=eq.2) only one of the selects gets the result of the query ( space.zones will be empty and space.stores will have the result).
if you select and filter with alias (as in the url above) space.zone and space.stores will both have the same result instead of space.zones having only space.zone.zone_type_id=eq.2 and space.stores space.zone.zone_type_id=eq.3.
The text was updated successfully, but these errors were encountered: