aggify 0.2.6__tar.gz → 0.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aggify
3
- Version: 0.2.6
3
+ Version: 0.2.7
4
4
  Summary: A MongoDB aggregation generator for Mongoengine
5
5
  Home-page: https://github.com/Aggify/aggify
6
6
  Author: SeYeD.Dev
@@ -495,6 +495,39 @@ class Aggify:
495
495
 
496
496
  return merged_pipeline
497
497
 
498
+ # check_fields_exist(self.base_model, let) # noqa
499
+ def get_field_name_recursively(self, field: str) -> str:
500
+ """
501
+ Recursively fetch the field name by following the hierarchy indicated by the field parameter.
502
+
503
+ The function traverses the field hierarchy indicated by double underscores in the field parameter.
504
+ At each level, it checks if the field exists and then fetches the database field name for it.
505
+ The entire hierarchy is then joined using a dot (.) separator.
506
+
507
+ Parameters:
508
+ - field (str): A string indicating the hierarchy of fields, separated by double underscores.
509
+
510
+ Returns:
511
+ - str: A dot-separated string representing the full path to the field in the database.
512
+ """
513
+
514
+ field_name = []
515
+ prev_base = self.base_model
516
+
517
+ # Split the field based on double underscores and process each item
518
+ for index, item in enumerate(field.split("__")):
519
+ # Ensure the field exists at the current level of hierarchy
520
+ check_fields_exist(prev_base, [item]) # noqa
521
+
522
+ # Append the database field name to the field_name list
523
+ field_name.append(get_db_field(prev_base, item))
524
+
525
+ # Move to the next level in the model hierarchy
526
+ prev_base = self.get_model_field(prev_base, item)
527
+
528
+ # Join the entire hierarchy using dots and return
529
+ return ".".join(field_name)
530
+
498
531
  @last_out_stage_check
499
532
  def lookup(
500
533
  self,
@@ -544,11 +577,12 @@ class Aggify:
544
577
  else:
545
578
  if not query:
546
579
  raise InvalidArgument(expected_list=["query"])
547
- check_fields_exist(self.base_model, let) # noqa
580
+
548
581
  let_dict = {
549
- field: f"${get_db_field(self.base_model, field)}" # noqa
550
- for field in let # noqa
582
+ field: f"${get_db_field(self.base_model, self.get_field_name_recursively(field))}" # noqa
583
+ for field in let
551
584
  }
585
+
552
586
  for q in query:
553
587
  # Construct the match stage for each query
554
588
  if isinstance(q, Q):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aggify"
3
- version = "0.2.6"
3
+ version = "0.2.7"
4
4
  authors = ["SeYeD.Dev <me@seyed.dev>"]
5
5
  repository = "https://github.com/Aggify/aggify"
6
6
  documentation = "https://github.com/Aggify/aggify/docs"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes