feat: implement proper merging for collections

This commit is contained in:
Hellow
2023-10-24 13:32:26 +02:00
parent 208d6943b4
commit 92258e4dce
4 changed files with 14 additions and 15 deletions

View File

@@ -25,7 +25,7 @@ class Collection(Generic[T]):
self.extend(data)
def _map_element(self, __object: T, no_append: bool = True):
def _map_element(self, __object: T, no_append: bool = False):
for name, value in __object.indexing_values:
if value is None:
continue
@@ -62,8 +62,7 @@ class Collection(Generic[T]):
return self
for collection in self.contained_collections:
if collection._contained_in_self(__object):
return collection
return collection._contained_in(__object)
return None
@@ -80,13 +79,16 @@ class Collection(Generic[T]):
if value is None:
continue
if value in self._indexed_values[name]:
existing_object = self._indexed_to_objects[value]
existing_object = self._indexed_to_objects[value][0]
break
if existing_object is None:
return None
existing_object.merge(__object, replace_all_refs=True)
existing_object.merge(__object)
replace_all_refs(existing_object, __object)
print(existing_object, __object)
if existing_object is not __object:
raise ValueError("This should NEVER happen. Merging doesn't work.")

View File

@@ -7,7 +7,6 @@ from .metadata import Metadata
from .option import Options
from ..utils.shared import HIGHEST_ID
from ..utils.config import main_settings, logging_settings
from ..utils.functions import replace_all_refs
LOGGER = logging_settings["object_logger"]
@@ -146,7 +145,7 @@ class DatabaseObject:
return list()
def merge(self, other, override: bool = False, replace_all_refs: bool = False):
def merge(self, other, override: bool = False):
if other is None:
return
@@ -169,9 +168,6 @@ class DatabaseObject:
if override or getattr(self, simple_attribute) == default_value:
setattr(self, simple_attribute, getattr(other, simple_attribute))
if replace_all_refs:
replace_all_refs(self, other)
def strip_details(self):
for collection in type(self).DOWNWARDS_COLLECTION_STRING_ATTRIBUTES:
getattr(self, collection).clear()