Skip to content

Commit

Permalink
Limit to 1 child filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed May 4, 2022
1 parent c7677eb commit 3a957fe
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions store/postgres/src/relational_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ impl<'a> QueryFilter<'a> {
table: &'a Table,
layout: &'a Layout,
) -> Result<Self, StoreError> {
Self::valid_attributes(filter, table, layout)?;
Self::valid_attributes(filter, table, layout, false)?;

Ok(QueryFilter {
filter,
Expand Down Expand Up @@ -953,7 +953,7 @@ impl<'a> QueryFilter<'a> {
/// inner join child1 c1 ON ( c1.id = parent.child_id AND c1.block_range @> $block )
/// inner join child2 c2 ON ( c2.id = parent.child_id AND c2.block_range @> $block )
///
pub fn walk_joins(&self, block: BlockNumber, mut out: AstPass<Pg>) -> QueryResult<()> {
pub fn walk_joins_ast(&self, block: BlockNumber, mut out: AstPass<Pg>) -> QueryResult<()> {
out.unsafe_to_cache_prepared();
self.visit_child_filters(block, self.filter, out)
.map_err(|e| DieselError::QueryBuilderError(Box::new(e)))?;
Expand All @@ -964,16 +964,20 @@ impl<'a> QueryFilter<'a> {
filter: &'a EntityFilter,
table: &'a Table,
layout: &'a Layout,
child_filter_ancestor: bool,
) -> Result<(), StoreError> {
use EntityFilter::*;
match filter {
And(filters) | Or(filters) => {
for filter in filters {
Self::valid_attributes(filter, table, layout)?;
Self::valid_attributes(filter, table, layout, child_filter_ancestor)?;
}
}
Child(_, entity, child_filter) => {
Self::valid_attributes(child_filter, layout.table_for_entity(entity)?, layout)?;
if child_filter_ancestor {
return Err(StoreError::QueryExecutionError("Only a single level sub filter is allowed".to_string()))
}
Self::valid_attributes(child_filter, layout.table_for_entity(entity)?, layout, true)?;
}
// This is a special case since we want to allow passing "block" column filter, but we dont
// want to fail/error when this is passed here, since this column is not really an entity column.
Expand Down Expand Up @@ -2805,7 +2809,7 @@ impl<'a> FilterQuery<'a> {
out.push_sql(" c");

if let Some(filter) = table_filter {
filter.walk_joins(self.block, out.reborrow())?;
filter.walk_joins_ast(self.block, out.reborrow())?;
}

out.push_sql("\n where ");
Expand Down

0 comments on commit 3a957fe

Please sign in to comment.