diff --git a/fixtures/queryer.json b/fixtures/queryer.json index 9a8b4d9..d92a0ce 100644 --- a/fixtures/queryer.json +++ b/fixtures/queryer.json @@ -1246,8 +1246,7 @@ " )", " FROM agreego.entity entity_1", " WHERE", - " NOT entity_1.archived", - " AND entity_1.archived = ($1 #>> '{}')::BOOLEAN", + " entity_1.archived = ($1 #>> '{}')::BOOLEAN", " AND entity_1.archived <> ($2 #>> '{}')::BOOLEAN", " AND entity_1.created_at = ($3 #>> '{}')::TIMESTAMPTZ", " AND entity_1.created_at > ($4 #>> '{}')::TIMESTAMPTZ", @@ -1718,8 +1717,7 @@ " JOIN agreego.organization organization_2 ON organization_2.id = entity_1.id", " JOIN agreego.person person_3 ON person_3.id = organization_2.id", " WHERE", - " NOT entity_1.archived", - " AND person_3.age = ($1 #>> '{}')::NUMERIC", + " person_3.age = ($1 #>> '{}')::NUMERIC", " AND person_3.age > ($2 #>> '{}')::NUMERIC", " AND person_3.age >= ($3 #>> '{}')::NUMERIC", " AND person_3.age < ($4 #>> '{}')::NUMERIC", @@ -2702,4 +2700,4 @@ } ] } -] \ No newline at end of file +] diff --git a/src/queryer/compiler.rs b/src/queryer/compiler.rs index 6c26986..7def47d 100644 --- a/src/queryer/compiler.rs +++ b/src/queryer/compiler.rs @@ -578,8 +578,20 @@ impl<'a> Compiler<'a> { let mut where_clauses = Vec::new(); // Dynamically apply the 'active-only' default ONLY if the client - // didn't explicitly request to filter on 'archived' themselves! - let has_archived_override = self.filter_keys.iter().any(|k| k == "archived"); + // didn't explicitly request to filter on 'archived' themselves — for THIS node. + // Keys arrive as "path/field:$op" (extract_filters), so match this node's own archived + // path, never the bare name: compared to "archived" alone it never matched (an explicit + // archived filter could not return archived rows), and matched on any key it would lift + // the default from every nested include the filter never mentioned. + let archived_path = if node.ast_path.is_empty() { + "archived".to_string() + } else { + format!("{}/archived", node.ast_path) + }; + let has_archived_override = self + .filter_keys + .iter() + .any(|k| k.split(':').next().unwrap_or(k) == archived_path); if !has_archived_override { where_clauses.push(format!("NOT {}.archived", entity_alias));