@@ -321,6 +321,7 @@ pub struct EntityFilter {
321321 id : Option < PropFilter < String > > ,
322322 attributes : Vec < AttributeFilter > ,
323323 relations : Option < EntityRelationFilter > ,
324+ space_id : Option < PropFilter < String > > ,
324325}
325326
326327impl EntityFilter {
@@ -354,8 +355,10 @@ impl EntityFilter {
354355
355356 /// Applies a global space_id to all sub-filters (i.e.: attribute and relation filters).
356357 /// If a space_id is already set in a sub-filter, it will be overwritten.
357- pub fn with_space_id ( mut self , space_id : impl Into < String > ) -> Self {
358+ pub fn space_id ( mut self , space_id : impl Into < String > ) -> Self {
358359 let space_id = space_id. into ( ) ;
360+ self . space_id = Some ( prop_filter:: value ( space_id. clone ( ) ) ) ;
361+
359362 for attribute in & mut self . attributes {
360363 attribute. space_id_mut ( prop_filter:: value ( & space_id) ) ;
361364 }
@@ -375,8 +378,16 @@ impl EntityFilter {
375378 query_part. merge_mut ( id. into_query_part ( & node_var, "id" ) ) ;
376379 }
377380
378- for attribute in self . attributes {
379- query_part. merge_mut ( attribute. into_query_part ( & node_var) ) ;
381+ if self . attributes . is_empty ( ) {
382+ if let Some ( space_id) = self . space_id {
383+ query_part = query_part
384+ . match_clause ( format ! ( "({node_var}) -[attribute:ATTRIBUTE]- (:Attribute)" , ) )
385+ . merge ( space_id. into_query_part ( "attribute" , "space_id" ) ) ;
386+ }
387+ } else {
388+ for attribute in self . attributes {
389+ query_part. merge_mut ( attribute. into_query_part ( & node_var) ) ;
390+ }
380391 }
381392
382393 if let Some ( relations) = self . relations {
0 commit comments